Don't allow binding patterns to bind keywords

Closes #1586
This commit is contained in:
Marijn Haverbeke
2012-02-10 15:48:25 +01:00
parent fe8a31e569
commit 7f1ea3ef6a
3 changed files with 14 additions and 24 deletions

View File

@@ -666,6 +666,15 @@ fn parse_path(p: parser) -> @ast::path {
{global: global, idents: ids, types: []});
}
fn parse_value_path(p: parser) -> @ast::path {
let pt = parse_path(p);
let last_word = pt.node.idents[vec::len(pt.node.idents)-1u];
if p.bad_expr_words.contains_key(last_word) {
p.fatal("found " + last_word + " in expression position");
}
pt
}
fn parse_path_and_ty_param_substs(p: parser, colons: bool) -> @ast::path {
let lo = p.span.lo;
let path = parse_path(p);
@@ -1510,11 +1519,11 @@ fn parse_pat(p: parser) -> @ast::pat {
pat = ast::pat_lit(val);
}
} else if is_plain_ident(p) &&
alt p.look_ahead(1u) {
token::LPAREN | token::LBRACKET | token::LT { false }
_ { true }
} {
let name = parse_path(p);
alt p.look_ahead(1u) {
token::LPAREN | token::LBRACKET | token::LT { false }
_ { true }
} {
let name = parse_value_path(p);
let sub = if eat(p, token::AT) { some(parse_pat(p)) }
else { none };
pat = ast::pat_ident(name, sub);