Debian Codegraph @

tests/cli/component-model/instantiate.wast

raw
1 ;; RUN: wast --assert default --snapshot tests/snapshots % -f cm-values
2
3 (component
4 (import "a" (core module $m))
5 (core instance $a (instantiate $m))
6 )
7
8 (component
9 (import "a" (func $i))
10 (import "b" (component $c (import "a" (func))))
11 (instance (instantiate $c (with "a" (func $i))))
12 )
13
14 (component
15 (import "a" (value $i string))
16 (import "b" (component $c (import "a" (value string))))
17 (instance (instantiate $c (with "a" (value $i))))
18 )
19
20 (component
21 (import "a" (component $i))
22 (import "b" (component $c (import "a" (component))))
23 (instance (instantiate $c (with "a" (component $i))))
24 )
25
26 (component
27 (import "a" (core module $i))
28 (import "b" (component $c (import "a" (core module))))
29 (instance (instantiate $c (with "a" (core module $i))))
30 )
31
32 (component
33 (import "a" (instance $i))
34 (import "b" (component $c (import "a" (instance))))
35 (instance (instantiate $c (with "a" (instance $i))))
36 )
37
38 (component
39 (import "a" (core module $m
40 (import "" "a" (func))
41 (import "" "b" (global i32))
42 (import "" "c" (table 1 funcref))
43 (import "" "d" (memory 1))
44 ))
45 (import "b" (core module $m2
46 (export "a" (func))
47 (export "b" (global i32))
48 (export "c" (table 1 funcref))
49 (export "d" (memory 1))
50 ))
51 (core instance $x (instantiate $m2))
52 (core instance (instantiate $m (with "" (instance $x))))
53 )
54
55 (component
56 (import "a" (core module $m
57 (import "" "d" (func))
58 (import "" "c" (global i32))
59 (import "" "b" (table 1 funcref))
60 (import "" "a" (memory 1))
61 ))
62 (import "b" (core module $m2
63 (export "a" (func))
64 (export "b" (global i32))
65 (export "c" (table 1 funcref))
66 (export "d" (memory 1))
67 ))
68 (core instance $x (instantiate $m2))
69
70 (core instance (instantiate $m (with "" (instance
71 (export "d" (func $x "a"))
72 (export "c" (global $x "b"))
73 (export "b" (table $x "c"))
74 (export "a" (memory $x "d"))
75 ))))
76 )
77
78 (component
79 (type $t string)
80 (import "a" (value (type $t)))
81 (component $c (import "a" (value string)) (export "b" (value 0)))
82 (instance (instantiate $c (with "a" (value 0))))
83 )
84
85 (component
86 (import "a" (component $m
87 (import "a" (instance
88 (export "a" (core module))
89 ))
90 ))
91 (import "b" (component $m2
92 (export "b" (core module))
93 ))
94 (instance $x (instantiate $m2))
95
96 (instance (instantiate $m (with "a" (instance
97 (export "a" (core module $x "b"))
98 ))))
99 )
100
101 (component
102 (import "a" (component $c
103 (import "a" (core module))
104 (import "b" (func))
105 (import "c" (component))
106 (import "d" (instance))
107 (import "e" (value string))
108 ))
109 (core module $m (import "b"))
110 (func $f (import "c"))
111 (component $c2 (import "d"))
112 (instance $i (import "e"))
113 (import "f" (value $v string))
114
115 (instance
116 (instantiate $c
117 (with "a" (core module $m))
118 (with "b" (func $f))
119 (with "c" (component $c2))
120 (with "d" (instance $i))
121 (with "e" (value $v))
122 )
123 )
124
125 (core instance $c (instantiate $m))
126 (core instance (instantiate $m))
127
128 ;; inline exports/imports
129 (type $empty (instance))
130 (instance $d (import "g") (type $empty))
131 (instance (import "h"))
132 (instance (import "i")
133 (export "x" (func)))
134 (instance (export "j") (export "k") (import "x"))
135 )
136
137 (assert_invalid
138 (component
139 (core instance (instantiate 0))
140 )
141 "unknown module")
142 (assert_invalid
143 (component
144 (instance (instantiate 0))
145 )
146 "unknown component")
147 (assert_invalid
148 (component
149 (import "a" (core module))
150 (core instance (instantiate 1))
151 )
152 "unknown module")
153
154 (component
155 (import "a" (func $f))
156 (import "b" (component $c))
157 (instance (instantiate $c (with "a" (func $f))))
158 )
159 (assert_invalid
160 (component
161 (import "a" (core module $m (import "" "" (func))))
162 (core instance (instantiate $m))
163 )
164 "missing module instantiation argument")
165 (assert_invalid
166 (component
167 (import "a" (component $m (import "a" (func))))
168 (instance (instantiate $m))
169 )
170 "missing import named `a`")
171
172 (assert_invalid
173 (component
174 (import "a" (component $m
175 (import "a" (func))
176 ))
177 (import "b" (component $c))
178 (instance $i (instantiate $m (with "a" (component $c))))
179 )
180 "expected func, found component")
181
182 (assert_invalid
183 (component
184 (import "a" (component $m
185 (import "a" (func))
186 ))
187 (import "b" (func $f (result string)))
188 (instance $i (instantiate $m (with "a" (func $f))))
189 )
190 "expected a result, found none")
191
192 (assert_invalid
193 (component
194 (import "a" (component $m
195 (import "a" (func))
196 ))
197 (import "b" (func (param "i" string)))
198 (instance $i (instantiate $m (with "a" (func 0))))
199 )
200 "expected 0 parameters, found 1")
201
202 (assert_invalid
203 (component
204 (import "a" (component $m
205 (import "a" (core module
206 (import "" "" (func))
207 ))
208 ))
209 (import "b" (core module $i
210 (import "" "" (global i32))
211 ))
212 (instance $i (instantiate $m (with "a" (core module $i))))
213 )
214 "type mismatch in import `::`")
215
216 (assert_invalid
217 (component
218 (import "a" (component $m
219 (import "a" (core module))
220 ))
221 (import "b" (core module $i
222 (import "" "foobar" (global i32))
223 ))
224 (instance $i (instantiate $m (with "a" (core module $i))))
225 )
226 "missing expected import `::foobar`")
227 (assert_invalid
228 (component
229 (import "a" (component $m
230 (import "a" (core module (export "x" (func))))
231 ))
232 (import "b" (core module $i))
233 (instance $i (instantiate $m (with "a" (core module $i))))
234 )
235 "missing expected export `x`")
236
237 ;; it's ok to give a module with fewer imports
238 (component
239 (import "a" (component $m
240 (import "a" (core module
241 (import "" "" (global i32))
242 (import "" "f" (func))
243 ))
244 ))
245 (import "b" (core module $i
246 (import "" "" (global i32))
247 ))
248 (instance $i (instantiate $m (with "a" (core module $i))))
249 )
250
251 ;; export subsets
252 (component
253 (import "a" (component $m
254 (import "a" (core module
255 (export "" (func))
256 ))
257 ))
258 (import "b" (core module $i
259 (export "" (func))
260 (export "a" (func))
261 ))
262 (instance $i (instantiate $m (with "a" (core module $i))))
263 )
264 (component
265 (import "a" (component $m
266 (import "a" (instance
267 (export "a" (func))
268 ))
269 ))
270 (import "b" (instance $i
271 (export "a" (func))
272 (export "b" (func))
273 ))
274 (instance (instantiate $m (with "a" (instance $i))))
275 )
276
277
278 ;; ============================================================================
279 ;; core wasm type checking
280
281 (assert_invalid
282 (component
283 (import "m1" (core module $m1 (import "" "" (func))))
284 (import "m2" (core module $m2 (export "" (func (param i32)))))
285 (core instance $i (instantiate $m2))
286 (core instance (instantiate $m1 (with "" (instance $i))))
287 )
288 "expected: (func)")
289 (assert_invalid
290 (component
291 (import "m1" (core module $m1 (import "" "" (func))))
292 (import "m2" (core module $m2 (export "" (func (result i32)))))
293 (core instance $i (instantiate $m2))
294 (core instance (instantiate $m1 (with "" (instance $i))))
295 )
296 "expected: (func)")
297 (assert_invalid
298 (component
299 (import "m1" (core module $m1 (import "" "" (global i32))))
300 (import "m2" (core module $m2 (export "" (global i64))))
301 (core instance $i (instantiate $m2))
302 (core instance (instantiate $m1 (with "" (instance $i))))
303 )
304 "expected global type i32, found i64")
305 (assert_invalid
306 (component
307 (import "m1" (core module $m1 (import "" "" (table 1 funcref))))
308 (import "m2" (core module $m2 (export "" (table 2 externref))))
309 (core instance $i (instantiate $m2))
310 (core instance (instantiate $m1 (with "" (instance $i))))
311 )
312 "expected table element type funcref, found externref")
313 (assert_invalid
314 (component
315 (import "m1" (core module $m1 (import "" "" (table 1 2 funcref))))
316 (import "m2" (core module $m2 (export "" (table 2 funcref))))
317 (core instance $i (instantiate $m2))
318 (core instance (instantiate $m1 (with "" (instance $i))))
319 )
320 "mismatch in table limits")
321 (assert_invalid
322 (component
323 (import "m1" (core module $m1 (import "" "" (table 2 2 funcref))))
324 (import "m2" (core module $m2 (export "" (table 1 funcref))))
325 (core instance $i (instantiate $m2))
326 (core instance (instantiate $m1 (with "" (instance $i))))
327 )
328 "mismatch in table limits")
329 (assert_invalid
330 (component
331 (import "m1" (core module $m1 (import "" "" (table 2 2 funcref))))
332 (import "m2" (core module $m2 (export "" (table 2 3 funcref))))
333 (core instance $i (instantiate $m2))
334 (core instance (instantiate $m1 (with "" (instance $i))))
335 )
336 "mismatch in table limits")
337 (assert_invalid
338 (component
339 (import "m1" (core module $m1 (import "" "" (memory 1 2 shared))))
340 (import "m2" (core module $m2 (export "" (memory 1))))
341 (core instance $i (instantiate $m2))
342 (core instance (instantiate $m1 (with "" (instance $i))))
343 )
344 "mismatch in the shared flag for memories")
345 (assert_invalid
346 (component
347 (import "m1" (core module $m1 (import "" "" (memory 1))))
348 (import "m2" (core module $m2 (export "" (memory 0))))
349 (core instance $i (instantiate $m2))
350 (core instance (instantiate $m1 (with "" (instance $i))))
351 )
352 "mismatch in memory limits")
353 (assert_invalid
354 (component
355 (import "m1" (core module $m1 (export "g" (func))))
356 (component $c
357 (import "m" (core module (export "g" (global i32))))
358 )
359 (instance (instantiate $c (with "m" (core module $m1))))
360 )
361 "type mismatch in export `g`")
362
363 (assert_invalid
364 (component
365 (core instance (instantiate 0))
366 )
367 "unknown module")
368
369 (component
370 (component $m
371 (core module $sub (export "module")
372 (func $f (export "") (result i32)
373 i32.const 5))
374 )
375 (instance $a (instantiate $m))
376 (alias export $a "module" (core module $sub))
377 (core instance $b (instantiate $sub))
378
379 (core module $final
380 (import "" "" (func $b (result i32)))
381 (func (export "get") (result i32)
382 call $b))
383
384 (core instance (instantiate $final (with "" (instance $b))))
385 )
386
387 (assert_invalid
388 (component (instance $i (export "" (func 0))))
389 "function index out of bounds")
390
391 (assert_invalid
392 (component (instance (export "" (instance 0))))
393 "index out of bounds")
394
395 (assert_invalid
396 (component (instance $i (export "" (component 0))))
397 "index out of bounds")
398
399 (assert_invalid
400 (component (instance (export "" (instance 0))))
401 "index out of bounds")
402
403 (assert_invalid
404 (component (instance $i (export "" (core module 0))))
405 "index out of bounds")
406
407 (assert_invalid
408 (component (instance $i (export "" (value 0))))
409 "index out of bounds")
410
411 (assert_invalid
412 (component (core instance (export "" (func 0))))
413 "index out of bounds")
414
415 (assert_invalid
416 (component (core instance (export "" (table 0))))
417 "index out of bounds")
418
419 (assert_invalid
420 (component (core instance (export "" (global 0))))
421 "index out of bounds")
422
423 (assert_invalid
424 (component (core instance (export "" (memory 0))))
425 "index out of bounds")
426
427 (assert_invalid
428 (component
429 (core module $m)
430 (core instance $i (instantiate $m))
431 (core instance (instantiate $m
432 (with "" (instance $i))
433 (with "" (instance $i))
434 ))
435 )
436 "duplicate module instantiation argument named ``"
437 )
438
439 (assert_invalid
440 (component
441 (core module $m (func (export "")))
442 (core instance $i (instantiate $m))
443 (core instance (instantiate $m
444 (with "" (instance $i))
445 (with "" (instance $i))
446 ))
447 )
448 "duplicate module instantiation argument named ``")
449
450 (assert_invalid
451 (component
452 (core module $m1 (func (export "")))
453 (core module $m2 (import "" "" (global i32)))
454 (core instance $i (instantiate $m1))
455 (core instance (instantiate $m2
456 (with "" (instance $i))
457 ))
458 )
459 "expected global, found func")
460
461 (assert_invalid
462 (component
463 (component $m)
464 (instance $i (instantiate $m))
465 (instance (instantiate $m
466 (with "a" (instance $i))
467 (with "a" (instance $i))
468 ))
469 )
470 "instantiation argument `a` conflicts with previous argument `a`")
471
472 (assert_invalid
473 (component
474 (component $c (import "a" (func)))
475 (instance (instantiate $c
476 (with "a" (component $c))
477 ))
478 )
479 "expected func, found component")
480
481 (assert_invalid
482 (component
483 (component $c)
484 (instance (instantiate $c
485 (with "" (core module 0))
486 ))
487 )
488 "index out of bounds")
489
490 (assert_invalid
491 (component
492 (component $c)
493 (instance (instantiate $c
494 (with "" (value 0))
495 ))
496 )
497 "index out of bounds")
498
499 (assert_invalid
500 (component
501 (component $c)
502 (instance (instantiate $c
503 (with "" (instance 0))
504 ))
505 )
506 "index out of bounds")
507
508 (assert_invalid
509 (component
510 (component $c)
511 (instance (instantiate $c
512 (with "" (func 0))
513 ))
514 )
515 "index out of bounds")
516
517 (assert_invalid
518 (component
519 (component $c)
520 (instance (instantiate $c
521 (with "" (component 100))
522 ))
523 )
524 "index out of bounds")
525
526 (assert_invalid
527 (component
528 (component $c)
529 (instance
530 (export "a" (component $c))
531 (export "a" (component $c))
532 )
533 )
534 "export name `a` conflicts with previous name `a`")
535
536 (component
537 (import "a" (instance $i))
538 (import "b" (func $f))
539 (import "c" (component $c))
540 (import "d" (core module $m))
541 (import "e" (value $v string))
542 (instance
543 (export "a" (instance $i))
544 (export "b" (func $f))
545 (export "c" (component $c))
546 (export "d" (core module $m))
547 (export "e" (value $v))
548 )
549 )
550
551 (component
552 (core module $m
553 (func (export "1"))
554 (memory (export "2") 1)
555 (table (export "3") 1 funcref)
556 (global (export "4") i32 i32.const 0)
557 )
558 (core instance $i (instantiate $m))
559 (core instance
560 (export "a" (func $i "1"))
561 (export "b" (memory $i "2"))
562 (export "c" (table $i "3"))
563 (export "d" (global $i "4"))
564 )
565 )
566
567 (assert_invalid
568 (component
569 (core module $m (func (export "")))
570 (core instance $i (instantiate $m))
571 (core instance
572 (export "" (func $i ""))
573 (export "" (func $i ""))
574 )
575 )
576 "export name `` already defined")
577
578 (assert_invalid
579 (component
580 (component $c)
581 (instance $i (instantiate $c))
582 (export "a" (instance $i "a"))
583 )
584 "no export named `a`")
585
586 (assert_invalid
587 (component
588 (export "a" (instance 100 "a"))
589 )
590 "index out of bounds")
591
592 (assert_invalid
593 (component
594 (import "a" (core module $libc
595 (export "memory" (memory 1))
596 (export "table" (table 0 funcref))
597 (export "func" (func))
598 (export "global" (global i32))
599 (export "global mut" (global (mut i64)))
600 ))
601 (core instance $libc (instantiate $libc))
602 (alias core export $libc "memory" (core memory $mem))
603 (alias core export $libc "table" (core table $tbl))
604 (alias core export $libc "func" (core func $func))
605 (alias core export $libc "global" (core global $global))
606 (alias core export $libc "global mut" (core global $global_mut))
607
608 (import "x" (core module $needs_libc
609 (import "" "memory" (memory 1))
610 (import "" "table" (table 0 funcref))
611 (import "" "func" (func))
612 (import "" "global" (global i32))
613 (import "" "global mut" (global (mut i64)))
614 ))
615
616 (core instance
617 (instantiate $needs_libc
618 (with "" (instance (export "memory" (memory $mem))))
619 )
620 )
621 )
622 "module instantiation argument `` does not export an item named `table`")
623
624 ;; Ensure a type can be an instantiation argument
625 (component
626 (type (tuple u32 u32))
627 (import "a" (type (eq 0)))
628 (component
629 (type (tuple u32 u32))
630 (import "a" (type (eq 0)))
631 )
632 (instance (instantiate 0
633 (with "a" (type 1))
634 )
635 )
636 )
637
638 (assert_invalid
639 (component
640 (type $t (tuple string string))
641 (import "a" (type $a (eq $t)))
642 (component $c
643 (type $t (tuple u32 u32))
644 (import "a" (type (eq $t)))
645 )
646 (instance (instantiate $c
647 (with "a" (type $a))
648 )
649 )
650 )
651 "expected primitive `u32` found primitive `string`")
652
653
654 ;; subtyping for module imports reverses order of imports/exports for the
655 ;; subtyping check
656 ;;
657 ;; Here `C` imports a module, and the module itself imports a table of min size
658 ;; 1. A module import which imports a min-size table of 0, however, is valid to
659 ;; supply for this since it'll already be given at least 1 anyway.
660 ;;
661 ;; Similarly for exports `C` imports a module that exports a table of at least
662 ;; size 1. If it's given a module that exports a larger table that's ok too.
663 (component
664 (core module $a
665 (import "" "" (table 0 funcref))
666 (table (export "x") 2 funcref)
667 )
668 (component $C
669 (import "a" (core module
670 (import "" "" (table 1 funcref))
671 (export "x" (table 1 funcref))
672 ))
673 )
674 (instance (instantiate $C (with "a" (core module $a))))
675 )
676
677 ;; same as above but for memories
678 (component
679 (core module $a1 (import "" "" (memory 0)))
680 (core module $a2 (memory (export "x") 2))
681 (component $C
682 (import "a1" (core module (import "" "" (memory 1))))
683 (import "a2" (core module (export "x" (memory 1))))
684 )
685 (instance (instantiate $C
686 (with "a1" (core module $a1))
687 (with "a2" (core module $a2))
688 ))
689 )
690
691 (assert_invalid
692 (component
693 (import "x" (func $x (param "x" u32)))
694 (import "y" (component $c
695 (import "x" (func (param "y" u32)))
696 ))
697
698 (instance (instantiate $c (with "x" (func $x))))
699 )
700 "expected parameter named `y`, found `x`")
701 (assert_invalid
702 (component
703 (import "x" (func $x (param "x" u32)))
704 (import "y" (component $c
705 (import "x" (func (param "x" s32)))
706 ))
707
708 (instance (instantiate $c (with "x" (func $x))))
709 )
710 "type mismatch in function parameter `x`")
711 (assert_invalid
712 (component
713 (import "x" (func $x (result u32)))
714 (import "y" (component $c
715 (import "x" (func (result s32)))
716 ))
717
718 (instance (instantiate $c (with "x" (func $x))))
719 )
720 "type mismatch with result type")
721
722 (assert_invalid
723 (component
724 (import "x" (instance $x (export "a" (func))))
725 (import "y" (component $c
726 (import "x" (instance $x (export "a" (component))))
727 ))
728
729 (instance (instantiate $c (with "x" (instance $x))))
730 )
731 "type mismatch in instance export `a`")
732
733 (assert_invalid
734 (component
735 (import "y" (component $c
736 (type $t u32)
737 (import "x" (type (eq $t)))
738 ))
739
740 (type $x (record (field "f" u32)))
741 (instance (instantiate $c (with "x" (type $x))))
742 )
743 "expected primitive, found record")
744
745 (assert_invalid
746 (component
747 (import "y" (component $c
748 (type $t (record (field "f" u32)))
749 (import "x" (type (eq $t)))
750 ))
751
752 (type $x u32)
753 (instance (instantiate $c (with "x" (type $x))))
754 )
755 "expected record, found u32")
756
757 (assert_invalid
758 (component
759 (import "y" (component $c
760 (type $t (record (field "x" u32)))
761 (import "x" (type (eq $t)))
762 ))
763
764 (type $f (tuple u8))
765 (type $x (record (field "x" $f)))
766 (instance (instantiate $c (with "x" (type $x))))
767 )
768 "expected u32, found tuple")
769
770 (assert_invalid
771 (component
772 (import "y" (component $c
773 (type $f (option s32))
774 (type $t (record (field "x" $f)))
775 (import "x" (type (eq $t)))
776 ))
777
778 (type $x (record (field "x" u32)))
779 (instance (instantiate $c (with "x" (type $x))))
780 )
781 "type mismatch in record field `x`")
782
783 (assert_invalid
784 (component
785 (import "y" (component $c
786 (type $t (record (field "x" u32)))
787 (import "x" (type (eq $t)))
788 ))
789
790 (type $x (record (field "y" u32) (field "z" u64)))
791 (instance (instantiate $c (with "x" (type $x))))
792 )
793 "expected 1 fields, found 2")
794
795 (assert_invalid
796 (component
797 (import "y" (component $c
798 (type $t (record (field "a" u32)))
799 (import "x" (type (eq $t)))
800 ))
801
802 (type $x (record (field "b" u32)))
803 (instance (instantiate $c (with "x" (type $x))))
804 )
805 "expected field name `a`, found `b`")
806
807 (assert_invalid
808 (component
809 (import "y" (component $c
810 (type $t (variant (case "x" u32)))
811 (import "x" (type (eq $t)))
812 ))
813
814 (type $x (variant (case "x" u32) (case "y" u32)))
815 (instance (instantiate $c (with "x" (type $x))))
816 )
817 "expected 1 cases, found 2")
818
819 (assert_invalid
820 (component
821 (import "y" (component $c
822 (type $t (variant (case "x" u32)))
823 (import "x" (type (eq $t)))
824 ))
825
826 (type $x (variant (case "y" u32)))
827 (instance (instantiate $c (with "x" (type $x))))
828 )
829 "expected case named `x`, found `y`")
830
831 (assert_invalid
832 (component
833 (import "y" (component $c
834 (type $t (variant (case "x" u32)))
835 (import "x" (type (eq $t)))
836 ))
837
838 (type $x (variant (case "x")))
839 (instance (instantiate $c (with "x" (type $x))))
840 )
841 "expected case `x` to have a type, found none")
842
843 (assert_invalid
844 (component
845 (import "y" (component $c
846 (type $t (variant (case "x")))
847 (import "x" (type (eq $t)))
848 ))
849
850 (type $x (variant (case "x" u32)))
851 (instance (instantiate $c (with "x" (type $x))))
852 )
853 "expected case `x` to have no type")
854
855 (assert_invalid
856 (component
857 (import "y" (component $c
858 (type $t (variant (case "x" u32)))
859 (import "x" (type (eq $t)))
860 ))
861
862 (type $x (variant (case "x" s32)))
863 (instance (instantiate $c (with "x" (type $x))))
864 )
865 "type mismatch in variant case `x`")
866
867 (assert_invalid
868 (component
869 (import "y" (component $c
870 (type $t (tuple u8))
871 (import "x" (type (eq $t)))
872 ))
873
874 (type $x (tuple u32 u32))
875 (instance (instantiate $c (with "x" (type $x))))
876 )
877 "expected 1 types, found 2")
878
879 (assert_invalid
880 (component
881 (import "y" (component $c
882 (type $t (tuple u8))
883 (import "x" (type (eq $t)))
884 ))
885
886 (type $x (tuple u16))
887 (instance (instantiate $c (with "x" (type $x))))
888 )
889 "type mismatch in tuple field 0")
890
891 (assert_invalid
892 (component
893 (import "y" (component $c
894 (type $t (flags "a"))
895 (import "x" (type (eq $t)))
896 ))
897
898 (type $x (flags "x"))
899 (instance (instantiate $c (with "x" (type $x))))
900 )
901 "mismatch in flags elements")
902
903 (assert_invalid
904 (component
905 (import "y" (component $c
906 (type $t (enum "a"))
907 (import "x" (type (eq $t)))
908 ))
909
910 (type $x (enum "x"))
911 (instance (instantiate $c (with "x" (type $x))))
912 )
913 "mismatch in enum elements")
914
915 (assert_invalid
916 (component
917 (import "y" (component $c
918 (type $t (result s32))
919 (import "x" (type (eq $t)))
920 ))
921
922 (type $x (result u32))
923 (instance (instantiate $c (with "x" (type $x))))
924 )
925 "type mismatch in ok variant")
926
927 (assert_invalid
928 (component
929 (import "y" (component $c
930 (type $t (result (error s32)))
931 (import "x" (type (eq $t)))
932 ))
933
934 (type $x (result (error u32)))
935 (instance (instantiate $c (with "x" (type $x))))
936 )
937 "type mismatch in err variant")
938
939 (assert_invalid
940 (component
941 (import "y" (component $c
942 (type $t (result))
943 (import "x" (type (eq $t)))
944 ))
945
946 (type $x (result u32))
947 (instance (instantiate $c (with "x" (type $x))))
948 )
949 "expected ok type to not be present")
950
951 (assert_invalid
952 (component
953 (import "y" (component $c
954 (type $t (result u32))
955 (import "x" (type (eq $t)))
956 ))
957
958 (type $x (result))
959 (instance (instantiate $c (with "x" (type $x))))
960 )
961 "expected ok type, but found none")
962
963 (assert_invalid
964 (component
965 (import "y" (component $c
966 (type $t (result))
967 (import "x" (type (eq $t)))
968 ))
969
970 (type $x (result (error u32)))
971 (instance (instantiate $c (with "x" (type $x))))
972 )
973 "expected err type to not be present")
974
975 (assert_invalid
976 (component
977 (import "y" (component $c
978 (type $t (result (error u32)))
979 (import "x" (type (eq $t)))
980 ))
981
982 (type $x (result))
983 (instance (instantiate $c (with "x" (type $x))))
984 )
985 "expected err type, but found none")