;;; TOOL: run-interp
;;; ARGS*: --enable-reference-types

(module
  (table $t_func 1 anyfunc)
  (table $t_any 1 anyref)
  (elem $t_func funcref (ref.func 1) (ref.null))
  (elem $t_any anyref (ref.func 1) (ref.null))
  (global $g (mut anyref) (ref.null))

  (func $ref_null (export "ref_null") (result nullref)
    ref.null
  )

  (func $ref_is_null (export "ref_is_null") (result i32)
    global.get $g
    ref.is_null
  )

  (func $ref_func (export "ref_func") (result anyfunc)
    ref.func $ref_is_null
  )

  (func $table_set (export "table_set")
    i32.const 0
    call $ref_func
    table.set $t_func
  )

  (func (export "table_get") (result i32)
    call $table_set
    i32.const 0
    table.get $t_func
    ref.is_null
  )

  (func $global_set (export "global_set") (result anyref)
    ref.func $ref_is_null
    global.set $g
    global.get $g
  )
)
(;; STDOUT ;;;
ref_null() => nullref
ref_is_null() => i32:1
ref_func() => funcref:1
table_set() =>
table_get() => i32:0
global_set() => funcref:1
;;; STDOUT ;;)
