1;;! gc = true
2;;! function_references = true
3
4(module
5  (table $t1 2 funcref)
6  (elem (table $t1) (i32.const 0) func $nop)
7  (func $nop)
8
9  (func (export "t1") (param i32)
10    local.get 0
11    call_indirect $t1)
12  (func (export "t1-wrong-type") (param i32)
13    i32.const 0
14    local.get 0
15    call_indirect $t1 (param i32))
16
17  (type $empty (func))
18  (table $t2 2 (ref null $empty))
19  (elem (table $t2) (i32.const 0) (ref null $empty) (ref.func $nop))
20
21  (func (export "t2") (param i32)
22    local.get 0
23    call_indirect $t2)
24  (func (export "t2-wrong-type") (param i32)
25    i32.const 0
26    local.get 0
27    call_indirect $t2 (param i32))
28
29  (table $t3 2 (ref $empty) (ref.func $nop))
30
31  (func (export "t3") (param i32)
32    local.get 0
33    call_indirect $t3)
34  (func (export "t3-wrong-type") (param i32)
35    i32.const 0
36    local.get 0
37    call_indirect $t3 (param i32))
38)
39
40(assert_return (invoke "t1" (i32.const 0)))
41(assert_trap (invoke "t1" (i32.const 1)) "uninitialized element")
42(assert_trap (invoke "t1" (i32.const 2)) "out of bounds")
43(assert_trap (invoke "t1-wrong-type" (i32.const 0)) "call type mismatch")
44(assert_trap (invoke "t1-wrong-type" (i32.const 1)) "uninitialized element")
45(assert_trap (invoke "t1-wrong-type" (i32.const 2)) "out of bounds")
46(assert_return (invoke "t2" (i32.const 0)))
47(assert_trap (invoke "t2" (i32.const 1)) "uninitialized element")
48(assert_trap (invoke "t2" (i32.const 2)) "out of bounds")
49(assert_trap (invoke "t2-wrong-type" (i32.const 0)) "call type mismatch")
50(assert_trap (invoke "t2-wrong-type" (i32.const 1)) "uninitialized element")
51(assert_trap (invoke "t2-wrong-type" (i32.const 2)) "out of bounds")
52(assert_return (invoke "t3" (i32.const 0)))
53(assert_return (invoke "t3" (i32.const 1)))
54(assert_trap (invoke "t3" (i32.const 2)) "out of bounds")
55(assert_trap (invoke "t3-wrong-type" (i32.const 0)) "call type mismatch")
56(assert_trap (invoke "t3-wrong-type" (i32.const 1)) "call type mismatch")
57(assert_trap (invoke "t3-wrong-type" (i32.const 2)) "out of bounds")
58