提交 5e1a6dac 编写于 作者: T Tim Chevalier

Parse nullary ret correctly

ret is similar to fail: if not followed by an expression, it
should be parsed as a ret without an argument. The old version would
fail if ret was followed by a close paren (for example). Fixed it.

Closes #676.
上级 0c913e63
......@@ -948,15 +948,13 @@ fn parse_expr_opt(&parser p) -> option::t[@ast::expr] {
hi = e.span.hi;
ex = ast::expr_check(ast::unchecked, e);
} else if (eat_word(p, "ret")) {
alt (p.peek()) {
case (token::SEMI) { ex = ast::expr_ret(none); }
// Handle ret as the block result expression
case (token::RBRACE) { ex = ast::expr_ret(none); }
case (_) {
auto e = parse_expr(p);
hi = e.span.hi;
ex = ast::expr_ret(some(e));
}
if (can_begin_expr(p.peek())) {
auto e = parse_expr(p);
hi = e.span.hi;
ex = ast::expr_ret(some(e));
}
else {
ex = ast::expr_ret(none);
}
} else if (eat_word(p, "break")) {
ex = ast::expr_break;
......
// xfail-stage0
fn foo() {
if (ret) { }
}
fn main() { foo(); }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册