Better error on missing ';' in certain cases.

This commit is contained in:
Christoffer Lerno
2023-05-15 08:45:10 +02:00
parent 353a072b75
commit 3a725d1348
6 changed files with 22 additions and 7 deletions

View File

@@ -903,7 +903,7 @@ static Expr *parse_call_expr(ParseContext *c, Expr *left)
int force_inline = -1;
while (1)
{
if (!parse_attribute(c, &attr)) return poisoned_expr;
if (!parse_attribute(c, &attr, true)) return poisoned_expr;
if (!attr) break;
AttributeType attr_type = attribute_by_name(attr->name);

View File

@@ -923,8 +923,9 @@ Decl *parse_var_decl(ParseContext *c)
* attr_params ::= '(' attr_param (',' attr_param)* ')'
* attr_param ::= const_expr | '&' '[' ']' || '[' ']' '='?
*/
bool parse_attribute(ParseContext *c, Attr **attribute_ref)
bool parse_attribute(ParseContext *c, Attr **attribute_ref, bool expect_eos)
{
SourceSpan start_span = c->prev_span;
bool had_error;
Path *path;
if (!parse_path_prefix(c, &path)) return false;
@@ -933,7 +934,15 @@ bool parse_attribute(ParseContext *c, Attr **attribute_ref)
if (!tok_is(c, TOKEN_AT_IDENT) && !tok_is(c, TOKEN_AT_TYPE_IDENT))
{
// Started a path? If so hard error
if (path) RETURN_SEMA_ERROR_HERE("Expected an attribute name.");
if (path)
{
if (expect_eos)
{
sema_error_at_after(start_span, "Expected a ';' here.");
return false;
}
RETURN_SEMA_ERROR_HERE("Expected an attribute name.");
}
// Otherwise assume no attributes
*attribute_ref = NULL;
@@ -1033,7 +1042,7 @@ bool parse_attributes(ParseContext *c, Attr ***attributes_ref, Visibility *visib
while (1)
{
Attr *attr;
if (!parse_attribute(c, &attr)) return false;
if (!parse_attribute(c, &attr, false)) return false;
if (!attr) return true;
Visibility parsed_visibility = -1;
if (!attr->is_custom)

View File

@@ -1062,7 +1062,7 @@ static inline Ast *consume_eos(ParseContext *c, Ast *ast)
{
if (!try_consume(c, TOKEN_EOS))
{
sema_error_at_after(c->prev_span, "Expected ';'");
sema_error_at_after(c->prev_span, "Expected a ';' here.");
advance(c);
return poisoned_ast;
}

View File

@@ -47,7 +47,8 @@ Expr *parse_cond(ParseContext *c);
Expr *parse_assert_expr(ParseContext *c);
Ast* parse_compound_stmt(ParseContext *c);
Ast *parse_short_body(ParseContext *c, TypeInfoId return_type, bool require_eos);
bool parse_attribute(ParseContext *c, Attr **attribute_ref);
bool parse_attribute(ParseContext *c, Attr **attribute_ref, bool expect_eos);
bool parse_attributes(ParseContext *c, Attr ***attributes_ref, Visibility *visibility_ref);
bool parse_switch_body(ParseContext *c, Ast ***cases, TokenType case_type, TokenType default_type);

View File

@@ -1 +1 @@
#define COMPILER_VERSION "0.4.511"
#define COMPILER_VERSION "0.4.512"

View File

@@ -0,0 +1,5 @@
fn void main()
{
call() // #error: ';'
rl::bar();
}