diff options
| author | Patrick Walton <[email protected]> | 2010-10-14 15:02:35 -0700 |
|---|---|---|
| committer | Patrick Walton <[email protected]> | 2010-10-14 15:08:19 -0700 |
| commit | c7ab80f743b3e2d34bb702be787507418cc794a8 (patch) | |
| tree | cac4fb19306b207c7fe5397ccc3b419ff53277c7 /src | |
| parent | Fix crasher in rustc. (diff) | |
| download | rust-c7ab80f743b3e2d34bb702be787507418cc794a8.tar.xz rust-c7ab80f743b3e2d34bb702be787507418cc794a8.zip | |
Typecheck tags in "alt" patterns
Diffstat (limited to 'src')
| -rw-r--r-- | src/boot/me/type.ml | 2 | ||||
| -rw-r--r-- | src/test/compile-fail/alt-tag-nullary.rs | 12 | ||||
| -rw-r--r-- | src/test/compile-fail/alt-tag-unary.rs | 12 |
3 files changed, 26 insertions, 0 deletions
diff --git a/src/boot/me/type.ml b/src/boot/me/type.ml index 66dd240e..648618e7 100644 --- a/src/boot/me/type.ml +++ b/src/boot/me/type.ml @@ -903,8 +903,10 @@ let check_stmt (cx:Semant.ctxt) : (fn_ctx -> Ast.stmt -> unit) = let arg_tys = match constr_ty with Ast.TY_fn (ty_sig, _) -> + demand expected (get_slot_ty ty_sig.Ast.sig_output_slot); Array.map get_slot_ty ty_sig.Ast.sig_input_slots | Ast.TY_tag _ -> + demand expected constr_ty; [||] | _ -> type_error "constructor function" constr_ty in diff --git a/src/test/compile-fail/alt-tag-nullary.rs b/src/test/compile-fail/alt-tag-nullary.rs new file mode 100644 index 00000000..f55f67e9 --- /dev/null +++ b/src/test/compile-fail/alt-tag-nullary.rs @@ -0,0 +1,12 @@ +// error-pattern: mismatched types + +tag a { A; } +tag b { B; } + +fn main() { + let a x = A; + alt (x) { + case (B) {} + } +} + diff --git a/src/test/compile-fail/alt-tag-unary.rs b/src/test/compile-fail/alt-tag-unary.rs new file mode 100644 index 00000000..f2004896 --- /dev/null +++ b/src/test/compile-fail/alt-tag-unary.rs @@ -0,0 +1,12 @@ +// error-pattern: mismatched types + +tag a { A(int); } +tag b { B(int); } + +fn main() { + let a x = A(0); + alt (x) { + case (B(?y)) {} + } +} + |