Skip to content

Commit

Permalink
Fix inconsistency in ordering of patterns during alt compilation
Browse files Browse the repository at this point in the history
Closes #1153
  • Loading branch information
marijnh committed Nov 22, 2011
1 parent 5d6a74f commit bd16aac
Showing 1 changed file with 12 additions and 17 deletions.
29 changes: 12 additions & 17 deletions src/comp/middle/trans_alt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,9 @@ fn assoc(key: str, list: bind_map) -> option::t<ValueRef> {
type match_branch =
@{pats: [@ast::pat],
bound: bind_map,
data:
@{body: BasicBlockRef,
guard: option::t<@ast::expr>,
id_map: ast_util::pat_id_map}};
data: @{body: BasicBlockRef,
guard: option::t<@ast::expr>,
id_map: ast_util::pat_id_map}};
type match = [match_branch];

fn matches_always(p: @ast::pat) -> bool {
Expand All @@ -114,18 +113,15 @@ fn enter_match(m: match, col: uint, val: ValueRef, e: enter_pat) -> match {
for br: match_branch in m {
alt e(br.pats[col]) {
some(sub) {
let pats =
vec::slice(br.pats, 0u, col) + sub +
vec::slice(br.pats, col + 1u, vec::len(br.pats));
let new_br =
@{pats: pats,
bound:
alt br.pats[col].node {
ast::pat_bind(name) {
br.bound + [{ident: name, val: val}]
}
_ { br.bound }
} with *br};
let pats = sub + vec::slice(br.pats, 0u, col) +
vec::slice(br.pats, col + 1u, vec::len(br.pats));
let new_br = @{pats: pats,
bound: alt br.pats[col].node {
ast::pat_bind(name) {
br.bound + [{ident: name, val: val}]
}
_ { br.bound }
} with *br};
result += [new_br];
}
none. { }
Expand Down Expand Up @@ -386,7 +382,6 @@ fn compile_submatch(bcx: @block_ctxt, m: match, vals: [ValueRef], f: mk_fail,
let ccx = bcx.fcx.lcx.ccx;
let pat_id = 0;
for br: match_branch in m {

// Find a real id (we're adding placeholder wildcard patterns, but
// each column is guaranteed to have at least one real pattern)
if pat_id == 0 { pat_id = br.pats[col].id; }
Expand Down

0 comments on commit bd16aac

Please sign in to comment.