;; RUN: wast --assert default,snapshot-folded --snapshot tests/snapshots % -f stack-switching ;; This file tests validation only, focusing on GC types and subtyping. ;;;; ;;;;; WasmFX types ;;;; (module (type $f (func)) (type $ft1 (sub (func (param (ref $f)) (result (ref func))))) (type $ct1 (sub (cont $ft1))) (type $ft2 (func (param (ref any)) (result (ref func)))) (type $ct2 (cont $ft2)) (type $ft3 (sub $ft1 (func (param (ref func)) (result (ref $f))))) (type $ct3 (cont $ft3)) ;; Okay: Continuation types are covariant, have declared $ft3 <: $ft1 (type $ct_sub (sub $ct1 (cont $ft3))) (func $test (param $p1 (ref $ct1)) (param $p2 (ref $ct_sub)) ;; Okay: (ref $ct_sub) <: (ref $ct1) (local.set $p1 (local.get $p2)) ) ) (assert_invalid (module (type $f (func)) (type $ft1 (sub (func (param (ref $f)) (result (ref func))))) (type $ct1 (sub (cont $ft1))) (type $ft2 (func (param (ref func)) (result (ref $f)))) ;; Error: $ft2 and ft1 have compatible types, but have not declared $ft2 <: ft1 (type $error (sub $ct1 (cont $ft2))) ) "sub type must match super type" ) (assert_invalid (module (type $f (func)) (type $ft1 (sub (func (param (ref $f)) (result (ref func))))) (type $ct1 (sub (cont $ft1))) (type $ft2 (func (param (ref func)) (result (ref $f)))) (type $ct2 (cont $ft2)) (func $test (param $p1 (ref $ct1)) (param $p2 (ref $ct2)) ;; Error $ct2 and $ct1 have generally compatible types, ;; but have not declared $ft2 <: ft1 or $ct2 <: $ct1 ;; Thus, $ct2