Debian Codegraph @

tests/cli/component-model-gc/result-types.wast

raw
1 ;; RUN: wast --assert default --snapshot tests/snapshots % -f gc,cm-gc
2
3 ;; Basic.
4 (component
5 (type $result (result u32 (error u8)))
6
7 (core type $result (struct))
8 (core type $ty (func (param (ref $result))))
9
10 (import "i" (instance $i
11 (export "ty" (type $result' (eq $result)))
12 (export "f" (func (param "x" $result')))))
13 (core func (canon lower (func $i "f") gc (core-type $ty)))
14 )
15
16 ;; With a nullable reference.
17 (component
18 (type $result (result u32 (error u8)))
19
20 (core type $result (struct))
21 (core type $ty (func (param (ref null $result))))
22
23 (import "i" (instance $i
24 (export "ty" (type $result' (eq $result)))
25 (export "f" (func (param "x" $result')))))
26 (core func (canon lower (func $i "f") gc (core-type $ty)))
27 )
28
29 ;; With a custom rec group.
30 (component
31 (type $result (result u32 (error u8)))
32
33 (core rec
34 (type $result (struct))
35 (type $ty (func (param (ref null $result)))))
36
37 (import "i" (instance $i
38 (export "ty" (type $result' (eq $result)))
39 (export "f" (func (param "x" $result')))))
40 (core func (canon lower (func $i "f") gc (core-type $ty)))
41 )
42
43 ;; With a custom subtype.
44 (component
45 (type $result (result u32 (error u8)))
46
47 (core type $base (sub (struct)))
48 (core type $result (sub $base (struct)))
49 (core type $ty (func (param (ref null $result))))
50
51 (import "i" (instance $i
52 (export "ty" (type $result' (eq $result)))
53 (export "f" (func (param "x" $result')))))
54 (core func (canon lower (func $i "f") gc (core-type $ty)))
55 )
56
57 ;; Unexpected fields in struct type.
58 (assert_invalid
59 (component
60 (type $result (result u32 (error u8)))
61
62 (core type $result (struct (field i8) (field i8)))
63 (core type $ty (func (param (ref $result))))
64
65 (import "i" (instance $i
66 (export "ty" (type $result' (eq $result)))
67 (export "f" (func (param "x" $result')))))
68 (core func (canon lower (func $i "f") gc (core-type $ty)))
69 )
70 "expected to lower component `result` type to core `(ref null? (struct))`"
71 )
72
73 ;; Lowering into a non-struct.
74 (assert_invalid
75 (component
76 (type $result (result u32 (error u8)))
77
78 (core type $ty (func (param externref)))
79
80 (import "i" (instance $i
81 (export "ty" (type $result' (eq $result)))
82 (export "f" (func (param "x" $result')))))
83 (core func (canon lower (func $i "f") gc (core-type $ty)))
84 )
85 "expected to lower component `result` type to core `(ref null? (struct))`"
86 )