mirror of
https://github.com/odin-lang/Odin.git
synced 2025-12-29 09:24:33 +00:00
Disallow import declarations within a when statement
This commit is contained in:
@@ -4183,6 +4183,8 @@ gb_internal Ast *parse_when_stmt(AstFile *f) {
|
||||
syntax_error(f->curr_token, "Expected condition for when statement");
|
||||
}
|
||||
|
||||
bool was_in_when_statement = f->in_when_statement;
|
||||
f->in_when_statement = true;
|
||||
if (allow_token(f, Token_do)) {
|
||||
body = parse_do_body(f, cond ? ast_token(cond) : token, "then when statement");
|
||||
} else {
|
||||
@@ -4209,6 +4211,7 @@ gb_internal Ast *parse_when_stmt(AstFile *f) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
f->in_when_statement = was_in_when_statement;
|
||||
|
||||
return ast_when_stmt(f, token, cond, body, else_stmt);
|
||||
}
|
||||
@@ -4470,6 +4473,10 @@ gb_internal Ast *parse_import_decl(AstFile *f, ImportDeclKind kind) {
|
||||
array_add(&f->imports, s);
|
||||
}
|
||||
|
||||
if (f->in_when_statement) {
|
||||
syntax_error(import_name, "Cannot use 'import' within a 'when' statement. Prefer using the file suffixes (e.g. foo_windows.odin) or '//+build' tags");
|
||||
}
|
||||
|
||||
if (kind != ImportDecl_Standard) {
|
||||
syntax_error(import_name, "'using import' is not allowed, please use the import name explicitly");
|
||||
}
|
||||
|
||||
@@ -116,6 +116,7 @@ struct AstFile {
|
||||
bool allow_in_expr; // NOTE(bill): in expression are only allowed in certain cases
|
||||
bool in_foreign_block;
|
||||
bool allow_type;
|
||||
bool in_when_statement;
|
||||
|
||||
isize total_file_decl_count;
|
||||
isize delayed_decl_count;
|
||||
|
||||
Reference in New Issue
Block a user