|
| 1 | +;; Tests Explainer.md#external-visibility-of-types |
| 2 | + |
| 3 | +;; resources |
| 4 | + |
| 5 | +(component definition |
| 6 | + (core module $m (func (export "f") (result i32) unreachable)) |
| 7 | + (core instance $i (instantiate $m)) |
| 8 | + (type $R (resource (rep i32))) |
| 9 | + (func $f (result (own $R)) (canon lift (core func $i "f"))) |
| 10 | + (export $R' "r" (type $R)) |
| 11 | + (export "f" (func $f) (func (result (own $R')))) |
| 12 | + (func $f2 (result (own $R')) (canon lift (core func $i "f"))) |
| 13 | + (export "f2" (func $f2)) |
| 14 | + (import "r2" (type $R2 (sub resource))) |
| 15 | + (import "f3" (func $f3 (result (own $R2)))) |
| 16 | + (func $f4 (result (own $R2)) (canon lift (core func $i "f"))) |
| 17 | + (export "f4" (func $f4))) |
| 18 | + |
| 19 | +(assert_invalid |
| 20 | + (component |
| 21 | + (core module $m (func (export "f") (result i32) unreachable)) |
| 22 | + (core instance $i (instantiate $m)) |
| 23 | + (type $R (resource (rep i32))) |
| 24 | + (func $f (result (own $R)) (canon lift (core func $i "f"))) |
| 25 | + (export "f" (func $f))) |
| 26 | + "func not valid to be used as export") |
| 27 | + |
| 28 | +(assert_invalid |
| 29 | + (component |
| 30 | + (core module $m (func (export "f") (result i32) unreachable)) |
| 31 | + (core instance $i (instantiate $m)) |
| 32 | + (type $R (resource (rep i32))) |
| 33 | + (func $f (result (own $R)) (canon lift (core func $i "f"))) |
| 34 | + (export $R' "r" (type $R)) |
| 35 | + (export "f" (func $f))) |
| 36 | + "func not valid to be used as export") |
| 37 | + |
| 38 | +(assert_invalid |
| 39 | + (component |
| 40 | + (type $R (resource (rep i32))) |
| 41 | + (export $R' "r" (type $R)) |
| 42 | + (import "f" (func (result (own $R'))))) |
| 43 | + "func not valid to be used as import") |
| 44 | + |
| 45 | +(assert_invalid |
| 46 | + (component |
| 47 | + (type $R (resource (rep i32))) |
| 48 | + (import "f" (func (result (own $R))))) |
| 49 | + "func not valid to be used as import") |
| 50 | + |
| 51 | +;; records |
| 52 | + |
| 53 | +(component definition |
| 54 | + (core module $m (func (export "f") (result i32) unreachable)) |
| 55 | + (core instance $i (instantiate $m)) |
| 56 | + (type $Rec (record (field "x" u32))) |
| 57 | + (func $f (result $Rec) (canon lift (core func $i "f"))) |
| 58 | + (export $Rec' "rec" (type $Rec)) |
| 59 | + (export "f" (func $f) (func (result $Rec')))) |
| 60 | + |
| 61 | +(assert_invalid |
| 62 | + (component |
| 63 | + (core module $m (func (export "f") (result i32) unreachable)) |
| 64 | + (core instance $i (instantiate $m)) |
| 65 | + (type $Rec (record (field "x" u32))) |
| 66 | + (func $f (result $Rec) (canon lift (core func $i "f"))) |
| 67 | + (export "f" (func $f))) |
| 68 | + "func not valid to be used as export") |
| 69 | + |
| 70 | +(assert_invalid |
| 71 | + (component |
| 72 | + (core module $m (func (export "f") (result i32) unreachable)) |
| 73 | + (core instance $i (instantiate $m)) |
| 74 | + (type $Rec (record (field "x" u32))) |
| 75 | + (func $f (result $Rec) (canon lift (core func $i "f"))) |
| 76 | + (export $Rec' "rec" (type $Rec)) |
| 77 | + (export "f" (func $f))) |
| 78 | + "func not valid to be used as export") |
| 79 | + |
| 80 | +(component definition |
| 81 | + (core module $m (func (export "f") (result i32) unreachable)) |
| 82 | + (core instance $i (instantiate $m)) |
| 83 | + (type $R (resource (rep i32))) |
| 84 | + (export $R' "r" (type $R)) |
| 85 | + (type $Rec (record (field "r" (own $R')))) |
| 86 | + (export $Rec' "rec" (type $Rec)) |
| 87 | + (func $f (result $Rec') (canon lift (core func $i "f"))) |
| 88 | + (export "f" (func $f))) |
| 89 | + |
| 90 | +(assert_invalid |
| 91 | + (component |
| 92 | + (core module $m (func (export "f") (result i32) unreachable)) |
| 93 | + (core instance $i (instantiate $m)) |
| 94 | + (type $R (resource (rep i32))) |
| 95 | + (type $Rec (record (field "r" (own $R)))) |
| 96 | + (export $Rec' "rec" (type $Rec)) |
| 97 | + (func $f (result $Rec') (canon lift (core func $i "f"))) |
| 98 | + (export "f" (func $f))) |
| 99 | + "type not valid to be used as export") |
| 100 | + |
| 101 | +;; enums |
| 102 | + |
| 103 | +(component definition |
| 104 | + (core module $m (func (export "f") (result i32) unreachable)) |
| 105 | + (core instance $i (instantiate $m)) |
| 106 | + (type $E (enum "a" "b")) |
| 107 | + (func $f (result $E) (canon lift (core func $i "f"))) |
| 108 | + (export $E' "e" (type $E)) |
| 109 | + (export "f" (func $f) (func (result $E')))) |
| 110 | + |
| 111 | +(assert_invalid |
| 112 | + (component |
| 113 | + (core module $m (func (export "f") (result i32) unreachable)) |
| 114 | + (core instance $i (instantiate $m)) |
| 115 | + (type $E (enum "a" "b")) |
| 116 | + (func $f (result $E) (canon lift (core func $i "f"))) |
| 117 | + (export "f" (func $f))) |
| 118 | + "func not valid to be used as export") |
| 119 | + |
| 120 | +;; flags |
| 121 | + |
| 122 | +(component definition |
| 123 | + (core module $m (func (export "f") (result i32) unreachable)) |
| 124 | + (core instance $i (instantiate $m)) |
| 125 | + (type $Fl (flags "a" "b")) |
| 126 | + (func $f (result $Fl) (canon lift (core func $i "f"))) |
| 127 | + (export $Fl' "fl" (type $Fl)) |
| 128 | + (export "f" (func $f) (func (result $Fl')))) |
| 129 | + |
| 130 | +(assert_invalid |
| 131 | + (component |
| 132 | + (core module $m (func (export "f") (result i32) unreachable)) |
| 133 | + (core instance $i (instantiate $m)) |
| 134 | + (type $Fl (flags "a" "b")) |
| 135 | + (func $f (result $Fl) (canon lift (core func $i "f"))) |
| 136 | + (export "f" (func $f))) |
| 137 | + "func not valid to be used as export") |
| 138 | + |
| 139 | +;; variants |
| 140 | + |
| 141 | +(component definition |
| 142 | + (core module $m (func (export "f") (result i32) unreachable)) |
| 143 | + (core instance $i (instantiate $m)) |
| 144 | + (type $V (variant (case "a") (case "b"))) |
| 145 | + (func $f (result $V) (canon lift (core func $i "f"))) |
| 146 | + (export $V' "v" (type $V)) |
| 147 | + (export "f" (func $f) (func (result $V')))) |
| 148 | + |
| 149 | +(assert_invalid |
| 150 | + (component |
| 151 | + (core module $m (func (export "f") (result i32) unreachable)) |
| 152 | + (core instance $i (instantiate $m)) |
| 153 | + (type $V (variant (case "a") (case "b"))) |
| 154 | + (func $f (result $V) (canon lift (core func $i "f"))) |
| 155 | + (export "f" (func $f))) |
| 156 | + "func not valid to be used as export") |
| 157 | + |
| 158 | +;; tuples/options |
| 159 | + |
| 160 | +(component definition |
| 161 | + (core module $m (func (export "f") (param i32 i32 i32 i32))) |
| 162 | + (core instance $i (instantiate $m)) |
| 163 | + (func $f (param "a" (tuple u32 u32)) (param "b" (option u32)) |
| 164 | + (canon lift (core func $i "f"))) |
| 165 | + (export "f" (func $f))) |
| 166 | + |
| 167 | +(assert_invalid |
| 168 | + (component |
| 169 | + (core module $m (func (export "f") (result i32) unreachable)) |
| 170 | + (core instance $i (instantiate $m)) |
| 171 | + (type $R (resource (rep i32))) |
| 172 | + (func $f (result (tuple (own $R))) (canon lift (core func $i "f"))) |
| 173 | + (export "f" (func $f))) |
| 174 | + "func not valid to be used as export") |
| 175 | + |
| 176 | +(component definition |
| 177 | + (core module $m (func (export "f") (result i32) unreachable)) |
| 178 | + (core instance $i (instantiate $m)) |
| 179 | + (type $R (resource (rep i32))) |
| 180 | + (export $R' "r" (type $R)) |
| 181 | + (func $f (result (tuple (own $R'))) (canon lift (core func $i "f"))) |
| 182 | + (export "f" (func $f))) |
| 183 | + |
| 184 | +(assert_invalid |
| 185 | + (component |
| 186 | + (core module $m |
| 187 | + (memory (export "mem") 1) |
| 188 | + (func (export "f") (result i32) unreachable)) |
| 189 | + (core instance $i (instantiate $m)) |
| 190 | + (type $R (resource (rep i32))) |
| 191 | + (func $f (result (option (own $R))) (canon lift (core func $i "f") (memory $i "mem"))) |
| 192 | + (export "f" (func $f))) |
| 193 | + "func not valid to be used as export") |
| 194 | + |
| 195 | +(assert_invalid |
| 196 | + (component |
| 197 | + (core module $m |
| 198 | + (memory (export "mem") 1) |
| 199 | + (func (export "f") (result i32) unreachable)) |
| 200 | + (core instance $i (instantiate $m)) |
| 201 | + (type $Rec (record (field "x" u32))) |
| 202 | + (func $f (result (tuple $Rec u32)) (canon lift (core func $i "f") (memory $i "mem"))) |
| 203 | + (export "f" (func $f))) |
| 204 | + "func not valid to be used as export") |
| 205 | + |
| 206 | +;; bag-of-exports: |
| 207 | + |
| 208 | +(assert_invalid |
| 209 | + (component |
| 210 | + (core module $m (func (export "f") (result i32) unreachable)) |
| 211 | + (core instance $i (instantiate $m)) |
| 212 | + (type $R (resource (rep i32))) |
| 213 | + (func $f (result (own $R)) (canon lift (core func $i "f"))) |
| 214 | + (instance $bag (export "f" (func $f))) |
| 215 | + (export "bag" (instance $bag))) |
| 216 | + "instance not valid to be used as export") |
0 commit comments