mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Improve error message on import "foo", module "foo", and import statements out of order.
This commit is contained in:
committed by
Christoffer Lerno
parent
3173d09e56
commit
9ee24b5846
@@ -326,12 +326,19 @@ bool parse_module(Context *context)
|
||||
|
||||
bool is_private = try_consume(context, TOKEN_PRIVATE);
|
||||
|
||||
if (TOKEN_IS(TOKEN_STRING))
|
||||
{
|
||||
SEMA_TOKEN_ERROR(context->tok, "'module' should be followed by a plain identifier, not a string. Did you accidentally put the module name between \"\"?");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!TOKEN_IS(TOKEN_IDENT))
|
||||
{
|
||||
SEMA_TOKEN_ERROR(context->tok, "Module statement should be followed by the name of the module.");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Path *path = parse_module_path(context);
|
||||
|
||||
// Expect the module name
|
||||
@@ -1949,6 +1956,11 @@ static inline bool parse_import(Context *context)
|
||||
|
||||
if (!TOKEN_IS(TOKEN_IDENT))
|
||||
{
|
||||
if (TOKEN_IS(TOKEN_STRING))
|
||||
{
|
||||
SEMA_TOKEN_ERROR(context->tok, "An import should be followed by a plain identifier, not a string. Did you accidentally put the module name between \"\"?");
|
||||
return false;
|
||||
}
|
||||
SEMA_TOKEN_ERROR(context->tok, "Import statement should be followed by the name of the module to import.");
|
||||
return false;
|
||||
}
|
||||
@@ -2238,6 +2250,9 @@ Decl *parse_top_level_statement(Context *context)
|
||||
SEMA_TOKEN_ERROR(context->tok, "Compile time constant unexpectedly found.");
|
||||
}
|
||||
return poisoned_decl;
|
||||
case TOKEN_IMPORT:
|
||||
SEMA_TOKEN_ERROR(context->tok, "Imports are only allowed directly after the module declaration.");
|
||||
return poisoned_decl;
|
||||
default:
|
||||
// We could have included all fundamental types above, but do it here instead.
|
||||
if (!token_is_type(context->tok.type))
|
||||
|
||||
5
test/test_suite/import/import_error_out_of_order.c3
Normal file
5
test/test_suite/import/import_error_out_of_order.c3
Normal file
@@ -0,0 +1,5 @@
|
||||
module foo;
|
||||
|
||||
func void hello() {}
|
||||
|
||||
import bar; // #error: Imports are only allowed directly after the module declaration
|
||||
1
test/test_suite/import/import_error_string.c3
Normal file
1
test/test_suite/import/import_error_string.c3
Normal file
@@ -0,0 +1 @@
|
||||
import "Hello my friend"; // #error: An import should be followed by a plain identifier, not a string. Did you accidentally put the module name between ""?
|
||||
1
test/test_suite/module/module_error_string.c3
Normal file
1
test/test_suite/module/module_error_string.c3
Normal file
@@ -0,0 +1 @@
|
||||
module "Hello my friend"; // #error: 'module' should be followed by a plain identifier, not a string. Did you accidentally put the module name between ""?
|
||||
Reference in New Issue
Block a user