From 48a961867464689a23e7d21a101da9a04a151fef Mon Sep 17 00:00:00 2001 From: Andreas Rossberg Date: Wed, 18 Nov 2015 20:06:36 +0100 Subject: [PATCH 1/2] Tighter typing of Break --- ml-proto/spec/check.ml | 7 ++++--- ml-proto/test/labels.wast | 2 +- ml-proto/test/switch.wast | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/ml-proto/spec/check.ml b/ml-proto/spec/check.ml index e9de483ef0..cbca8d94ea 100644 --- a/ml-proto/spec/check.ml +++ b/ml-proto/spec/check.ml @@ -228,9 +228,10 @@ and check_exprs c ts es = with Invalid_argument _ -> error (Source.ats es) "arity mismatch" and check_expr_opt c et eo at = - match eo with - | Some e -> check_expr c et e - | None -> check_type None et at + match et, eo with + | Some t, Some e -> check_expr c et e + | None, None -> () + | _ -> error at "arity mismatch" and check_literal c et l = check_type (Some (type_value l.it)) et l.at diff --git a/ml-proto/test/labels.wast b/ml-proto/test/labels.wast index bdfde276a7..ba8dec693d 100644 --- a/ml-proto/test/labels.wast +++ b/ml-proto/test/labels.wast @@ -24,7 +24,7 @@ (loop $exit $cont (set_local $i (i32.add (get_local $i) (i32.const 1))) (if (i32.eq (get_local $i) (i32.const 5)) - (br $cont (i32.const -1)) + (br $cont) ) (if (i32.eq (get_local $i) (i32.const 8)) (br $exit (get_local $i)) diff --git a/ml-proto/test/switch.wast b/ml-proto/test/switch.wast index d357ca3d83..a731731b79 100644 --- a/ml-proto/test/switch.wast +++ b/ml-proto/test/switch.wast @@ -12,7 +12,7 @@ (case $2) ;; fallthrough (case $3 (set_local $j (i32.sub (i32.const 0) (get_local $i))) (br 0)) (case $4 (br 0)) - (case $5 (br 0 (set_local $j (i32.const 101)))) + (case $5 (set_local $j (i32.const 101)) (br 0)) (case $6 (set_local $j (i32.const 101))) ;; fallthrough (case $default (set_local $j (i32.const 102))) (case $7) From 6f6505b2cf43687f48cfdcf5138c778ce9d14472 Mon Sep 17 00:00:00 2001 From: Andreas Rossberg Date: Thu, 19 Nov 2015 11:44:24 +0100 Subject: [PATCH 2/2] Invalid test --- ml-proto/test/labels.wast | 1 + 1 file changed, 1 insertion(+) diff --git a/ml-proto/test/labels.wast b/ml-proto/test/labels.wast index ba8dec693d..a975d5995f 100644 --- a/ml-proto/test/labels.wast +++ b/ml-proto/test/labels.wast @@ -78,3 +78,4 @@ (assert_return (invoke "return" (i32.const 1)) (i32.const 2)) (assert_return (invoke "return" (i32.const 2)) (i32.const 2)) +(assert_invalid (module (func (loop $l (br $l (i32.const 0))))) "arity mismatch")