mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
A file with an inferred module may not contain additional other modules.
This commit is contained in:
@@ -26,6 +26,7 @@
|
||||
- `@assignable_to` is deprecated in favour of `$define`
|
||||
- Add `linklib-dir` to c3l-libraries to place their linked libraries in. Defaults to `linked-libs`
|
||||
- If the `os-arch` linked library doesn't exist, try with `os` for c3l libs.
|
||||
- A file with an inferred module may not contain additional other modules.
|
||||
|
||||
### Fixes
|
||||
- List.remove_at would incorrectly trigger ASAN.
|
||||
|
||||
@@ -1698,6 +1698,7 @@ struct CompilationUnit_
|
||||
bool is_interface_file;
|
||||
bool benchmark_by_default;
|
||||
bool test_by_default;
|
||||
bool module_generated;
|
||||
Attr **attr_links;
|
||||
Decl **generic_defines;
|
||||
Decl **ct_asserts;
|
||||
|
||||
@@ -121,7 +121,7 @@ bool context_set_module_from_filename(ParseContext *context)
|
||||
return false;
|
||||
}
|
||||
Path *path = CALLOCS(Path);
|
||||
path->span = INVALID_SPAN;
|
||||
path->span = context->span;
|
||||
path->module = module_name;
|
||||
path->len = scratch_buffer.len;
|
||||
return create_module_or_check_name(context->unit, path, NULL);
|
||||
|
||||
@@ -3190,6 +3190,7 @@ Decl *parse_top_level_statement(ParseContext *c, ParseContext **context_out)
|
||||
if (tok != TOKEN_MODULE && !c->unit->module)
|
||||
{
|
||||
if (!context_set_module_from_filename(c)) return poisoned_decl;
|
||||
c->unit->module_generated = true;
|
||||
// Pass the docs to the next thing.
|
||||
}
|
||||
|
||||
@@ -3230,6 +3231,14 @@ Decl *parse_top_level_statement(ParseContext *c, ParseContext **context_out)
|
||||
advance(c);
|
||||
if (c->unit->module)
|
||||
{
|
||||
if (c->unit->module_generated)
|
||||
{
|
||||
print_error_at(c->unit->module->name->span, "This file begins with an auto-generated module '%s', which isn't compatible with having other module sections, please start the file with an explicit 'module'.",
|
||||
c->unit->module->name->module);
|
||||
sema_note_prev_at(c->span, "This declaration creates the next module section.");
|
||||
c->unit->module_generated = false;
|
||||
return poisoned_decl;
|
||||
}
|
||||
// We might run into another module declaration. If so, create a new unit.
|
||||
ParseContext *new_context = CALLOCS(ParseContext);
|
||||
*new_context = *c;
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
import std;
|
||||
|
||||
module abort_test;
|
||||
|
||||
fn int main()
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
module okok;
|
||||
fn void main() {}
|
||||
module foo @private;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user