(module
  (type $t (func))
  (func (export "anyref") (result anyref) (ref.null any))
  (func (export "funcref") (result funcref) (ref.null func))
  (func (export "exnref") (result exnref) (ref.null exn))
  (func (export "externref") (result externref) (ref.null extern))
  (func (export "ref") (result (ref null $t)) (ref.null $t))

  (global anyref (ref.null any))
  (global funcref (ref.null func))
  (global exnref (ref.null exn))
  (global externref (ref.null extern))
  (global (ref null $t) (ref.null $t))
)

(assert_return (invoke "anyref") (ref.null any))
(assert_return (invoke "funcref") (ref.null func))
(assert_return (invoke "exnref") (ref.null exn))
(assert_return (invoke "externref") (ref.null extern))
(assert_return (invoke "ref") (ref.null))


(module
  (type $t (func))
  (global $null nullref (ref.null none))
  (global $nullfunc nullfuncref (ref.null nofunc))
  (global $nullexn nullexnref (ref.null noexn))
  (global $nullextern nullexternref (ref.null noextern))
  (func (export "anyref") (result anyref) (global.get $null))
  (func (export "nullref") (result nullref) (global.get $null))
  (func (export "funcref") (result funcref) (global.get $nullfunc))
  (func (export "nullfuncref") (result nullfuncref) (global.get $nullfunc))
  (func (export "exnref") (result exnref) (global.get $nullexn))
  (func (export "nullexnref") (result nullexnref) (global.get $nullexn))
  (func (export "externref") (result externref) (global.get $nullextern))
  (func (export "nullexternref") (result nullexternref) (global.get $nullextern))
  (func (export "ref") (result (ref null $t)) (global.get $nullfunc))

  (global anyref (ref.null any))
  (global anyref (ref.null none))
  (global funcref (ref.null func))
  (global funcref (ref.null nofunc))
  (global exnref (ref.null exn))
  (global exnref (ref.null noexn))
  (global externref (ref.null extern))
  (global externref (ref.null noextern))
  (global nullref (ref.null none))
  (global nullfuncref (ref.null nofunc))
  (global nullexnref (ref.null noexn))
  (global nullexternref (ref.null noextern))
  (global (ref null $t) (ref.null $t))
  (global (ref null $t) (ref.null nofunc))
)

(assert_return (invoke "anyref") (ref.null any))
(assert_return (invoke "anyref") (ref.null none))
(assert_return (invoke "anyref") (ref.null))
(assert_return (invoke "nullref") (ref.null any))
(assert_return (invoke "nullref") (ref.null none))
(assert_return (invoke "nullref") (ref.null))
(assert_return (invoke "funcref") (ref.null func))
(assert_return (invoke "funcref") (ref.null nofunc))
(assert_return (invoke "funcref") (ref.null))
(assert_return (invoke "nullfuncref") (ref.null func))
(assert_return (invoke "nullfuncref") (ref.null nofunc))
(assert_return (invoke "nullfuncref") (ref.null))
(assert_return (invoke "exnref") (ref.null exn))
(assert_return (invoke "exnref") (ref.null noexn))
(assert_return (invoke "exnref") (ref.null))
(assert_return (invoke "nullexnref") (ref.null exn))
(assert_return (invoke "nullexnref") (ref.null noexn))
(assert_return (invoke "nullexnref") (ref.null))
(assert_return (invoke "externref") (ref.null extern))
(assert_return (invoke "externref") (ref.null noextern))
(assert_return (invoke "externref") (ref.null))
(assert_return (invoke "nullexternref") (ref.null extern))
(assert_return (invoke "nullexternref") (ref.null noextern))
(assert_return (invoke "nullexternref") (ref.null))
(assert_return (invoke "ref") (ref.null func))
(assert_return (invoke "ref") (ref.null nofunc))
(assert_return (invoke "ref") (ref.null))
