mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Improve error reporting for define and function definition.
This commit is contained in:
@@ -1136,6 +1136,12 @@ static inline Decl *parse_global_declaration(ParseContext *c)
|
||||
}
|
||||
if (!parse_decl_initializer(c, decl, true)) return poisoned_decl;
|
||||
}
|
||||
else if (!decl->attributes && tok_is(c, TOKEN_LPAREN) && !threadlocal)
|
||||
{
|
||||
// Guess we forgot `fn`?
|
||||
sema_error_at(type->span, "This looks like the beginning of a function declaration but it's missing the initial `fn`. Did you forget it?");
|
||||
return poisoned_decl;
|
||||
}
|
||||
CONSUME_EOS_OR_RET(poisoned_decl);
|
||||
Attr **attributes = decl->attributes;
|
||||
if (attributes)
|
||||
@@ -1928,6 +1934,18 @@ static inline Decl *parse_define_ident(ParseContext *c)
|
||||
if (!params) return poisoned_decl;
|
||||
decl->define_decl.generic_params = params;
|
||||
}
|
||||
else if (!tok_is(c, TOKEN_EOS) && decl->define_decl.ident == kw_distinct)
|
||||
{
|
||||
if (token_is_any_type(c->tok))
|
||||
{
|
||||
SEMA_ERROR(decl, "A type name alias must start with an uppercase letter.");
|
||||
}
|
||||
else
|
||||
{
|
||||
sema_error_at(decl->define_decl.span, "'distinct' can only be used with types.");
|
||||
}
|
||||
return poisoned_decl;
|
||||
}
|
||||
RANGE_EXTEND_PREV(decl);
|
||||
CONSUME_EOS_OR_RET(poisoned_decl);
|
||||
return decl;
|
||||
|
||||
4
test/test_suite/distinct/distinct_parse_errors.c3
Normal file
4
test/test_suite/distinct/distinct_parse_errors.c3
Normal file
@@ -0,0 +1,4 @@
|
||||
import std::io;
|
||||
|
||||
define foo = distinct x; // #error: can only be used with types
|
||||
define bar = distinct int; // #error: type name alias must start with an uppercase
|
||||
1
test/test_suite/functions/missing_fn.c3
Normal file
1
test/test_suite/functions/missing_fn.c3
Normal file
@@ -0,0 +1 @@
|
||||
void foo(int x) {} // #error: This looks like the beginning of a function declaration
|
||||
Reference in New Issue
Block a user