Skip to content

Commit

Permalink
add missing typecheck for const pattern match arm
Browse files Browse the repository at this point in the history
Issue #4968
  • Loading branch information
youknowone committed Feb 18, 2013
1 parent a6945f2 commit 092b611
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/librustc/middle/typeck/check/_match.rs
Expand Up @@ -362,6 +362,7 @@ pub fn check_pat(pcx: pat_ctxt, pat: @ast::pat, expected: ty::t) {
ast::pat_ident(*) if pat_is_const(tcx.def_map, pat) => {
let const_did = ast_util::def_id_of_def(tcx.def_map.get(&pat.id));
let const_tpt = ty::lookup_item_type(tcx, const_did);
demand::suptype(fcx, pat.span, expected, const_tpt.ty);
fcx.write_ty(pat.id, const_tpt.ty);
}
ast::pat_ident(bm, name, sub) if pat_is_binding(tcx.def_map, pat) => {
Expand Down
17 changes: 17 additions & 0 deletions src/test/compile-fail/issue-4968.rs
@@ -0,0 +1,17 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// Regression test for issue #4968

const A: (int,int) = (4,2);
fn main() {
match 42 { A => () } //~ ERROR mismatched types: expected `<VI0>` but found `(int,int)` (expected integral variable but found tuple)
}

5 comments on commit 092b611

@bors
Copy link
Contributor

@bors bors commented on 092b611 Feb 19, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from catamorphism
at youknowone@092b611

@bors
Copy link
Contributor

@bors bors commented on 092b611 Feb 19, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging youknowone/rust/match_const_typecheck = 092b611 into auto

@bors
Copy link
Contributor

@bors bors commented on 092b611 Feb 19, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

youknowone/rust/match_const_typecheck = 092b611 merged ok, testing candidate = 24603af

@bors
Copy link
Contributor

@bors bors commented on 092b611 Feb 19, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bors
Copy link
Contributor

@bors bors commented on 092b611 Feb 19, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding incoming to auto = 24603af

Please sign in to comment.