mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Typecheck tags in "alt" patterns
This commit is contained in:
parent
f234750d80
commit
c7ab80f743
@ -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
|
||||
|
12
src/test/compile-fail/alt-tag-nullary.rs
Normal file
12
src/test/compile-fail/alt-tag-nullary.rs
Normal file
@ -0,0 +1,12 @@
|
||||
// error-pattern: mismatched types
|
||||
|
||||
tag a { A; }
|
||||
tag b { B; }
|
||||
|
||||
fn main() {
|
||||
let a x = A;
|
||||
alt (x) {
|
||||
case (B) {}
|
||||
}
|
||||
}
|
||||
|
12
src/test/compile-fail/alt-tag-unary.rs
Normal file
12
src/test/compile-fail/alt-tag-unary.rs
Normal file
@ -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)) {}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user