Skip to content

Commit 43f84a3

Browse files
committed
Test more catch subtyping
1 parent 0f7a95a commit 43f84a3

File tree

2 files changed

+64
-4
lines changed

2 files changed

+64
-4
lines changed

interpreter/valid/valid.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -939,11 +939,11 @@ and check_catch (c : context) (cc : catch) (ts : val_type list) at =
939939
| CatchRef (x1, x2) ->
940940
let TagT dt = tag c x1 in
941941
let FuncT (ts1, ts2) = as_func_str_type (expand_def_type dt) in
942-
match_target c (ts1 @ [RefT (Null, ExnHT)]) (label c x2) cc.at
942+
match_target c (ts1 @ [RefT (NoNull, ExnHT)]) (label c x2) cc.at
943943
| CatchAll x ->
944944
match_target c [] (label c x) cc.at
945945
| CatchAllRef x ->
946-
match_target c [RefT (Null, ExnHT)] (label c x) cc.at
946+
match_target c [RefT (NoNull, ExnHT)] (label c x) cc.at
947947

948948

949949
(* Functions & Constants *)

test/core/try_table.wast

Lines changed: 62 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -379,12 +379,72 @@
379379

380380
(tag $e (param (ref $t)))
381381
(func $throw (throw $e (ref.func $dummy)))
382-
(func (export "run") (result (ref null $t))
382+
383+
(func (export "catch") (result (ref null $t))
383384
(block $l (result (ref null $t))
384385
(try_table (catch $e $l) (call $throw))
385386
(unreachable)
386387
)
387388
)
389+
(func (export "catch_ref1") (result (ref null $t))
390+
(block $l (result (ref null $t) (ref exn))
391+
(try_table (catch_ref $e $l) (call $throw))
392+
(unreachable)
393+
)
394+
(drop)
395+
)
396+
(func (export "catch_ref2") (result (ref null $t))
397+
(block $l (result (ref null $t) (ref null exn))
398+
(try_table (catch_ref $e $l) (call $throw))
399+
(unreachable)
400+
)
401+
(drop)
402+
)
403+
(func (export "catch_all_ref1")
404+
(block $l (result (ref exn))
405+
(try_table (catch_all_ref $l) (call $throw))
406+
(unreachable)
407+
)
408+
(drop)
409+
)
410+
(func (export "catch_all_ref2")
411+
(block $l (result (ref null exn))
412+
(try_table (catch_all_ref $l) (call $throw))
413+
(unreachable)
414+
)
415+
(drop)
416+
)
388417
)
389418

390-
(assert_return (invoke "run") (ref.func))
419+
(assert_return (invoke "catch") (ref.func))
420+
(assert_return (invoke "catch_ref1") (ref.func))
421+
(assert_return (invoke "catch_ref2") (ref.func))
422+
(assert_return (invoke "catch_all_ref1"))
423+
(assert_return (invoke "catch_all_ref2"))
424+
425+
(assert_invalid
426+
(module
427+
(type $t (func))
428+
(tag $e (param (ref null $t)))
429+
(func (export "catch") (result (ref $t))
430+
(block $l (result (ref $t))
431+
(try_table (catch $e $l))
432+
(unreachable)
433+
)
434+
)
435+
)
436+
"type mismatch"
437+
)
438+
(assert_invalid
439+
(module
440+
(type $t (func))
441+
(tag $e (param (ref null $t)))
442+
(func (export "catch_ref") (result (ref $t))
443+
(block $l (result (ref $t) (ref exn))
444+
(try_table (catch $e $l))
445+
(unreachable)
446+
)
447+
)
448+
)
449+
"type mismatch"
450+
)

0 commit comments

Comments
 (0)