if (!skip_token (RIGHT_CURLY))
{
- Error error (t->get_locus (),
- "error may be from having an expression (as opposed to "
- "statement) in the body of the function but not last");
- add_error (std::move (error));
-
+ // We don't need to throw an error as it already reported by skip_token
skip_after_end_block ();
return tl::unexpected<Parse::Error::Node> (Parse::Error::Node::MALFORMED);
}
if (!expr)
{
- Error error (lexer.peek_token ()->get_locus (),
- "failed to parse expr in match arm in match expr");
- add_error (std::move (error));
-
- // skip somewhere?
+ /* We don't need to throw an error as it already reported by
+ * parse_expr
+ */
return tl::unexpected<Parse::Error::Node> (
Parse::Error::Node::CHILD_ERROR);
}
return ExprOrStmt (
std::make_unique<AST::ExprStmt> (std::move (expr.value ()),
t->get_locus (), false));
+
+ // Check if expr_without_block is properly terminated
+ if (expr.value ()->is_expr_without_block ()
+ && after_expr->get_id () != RIGHT_CURLY)
+ {
+ // expr_without_block must be followed by ';' or '}'
+ Error error (after_expr->get_locus (),
+ "expected %<;%> or %<}%> after expression, found %qs",
+ after_expr->get_token_description ());
+ add_error (std::move (error));
+ return tl::unexpected<Parse::Error::Node> (
+ Parse::Error::Node::MALFORMED);
+ }
}
// return expression