Skip to content

Commit

Permalink
Allow ^ suffix for non-recursive imports #1480.
Browse files Browse the repository at this point in the history
  • Loading branch information
lerno committed Sep 25, 2024
1 parent da47588 commit 413877b
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 4 deletions.
1 change: 1 addition & 0 deletions releasenotes.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
- Allow specifying an import module using `@wasm` #1305.
- Deprecated inline generic types outside of struct definitions and macros unless marked `@adhoc`.
- Improved method detection in earlier stages of checking.
- Allow `^` suffix for non-recursive imports #1480.

### Fixes
- Issue where a lambda wasn't correctly registered as external. #1408
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/compiler_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ typedef struct
{
Path *path;
bool import_private_as_public;
bool is_non_recurse;
Module *module;
} ImportDecl;

Expand Down Expand Up @@ -2133,7 +2134,7 @@ CompilationUnit * unit_create(File *file);
void unit_register_global_decl(CompilationUnit *unit, Decl *decl);
void unit_register_external_symbol(SemaContext *context, Decl *decl);

bool unit_add_import(CompilationUnit *unit, Path *path, bool private_import);
bool unit_add_import(CompilationUnit *unit, Path *path, bool private_import, bool is_non_recursive);
bool context_set_module_from_filename(ParseContext *context);
bool context_set_module(ParseContext *context, Path *path, const char **generic_parameters);
bool context_is_macro(SemaContext *context);
Expand Down
4 changes: 2 additions & 2 deletions src/compiler/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ void unit_register_global_decl(CompilationUnit *unit, Decl *decl)
}


bool unit_add_import(CompilationUnit *unit, Path *path, bool private_import)
bool unit_add_import(CompilationUnit *unit, Path *path, bool private_import, bool is_non_recursive)
{
DEBUG_LOG("SEMA: Add import of '%s'.", path->module);

Expand All @@ -281,7 +281,7 @@ bool unit_add_import(CompilationUnit *unit, Path *path, bool private_import)
import->decl_kind = DECL_IMPORT;
import->import.path = path;
import->import.import_private_as_public = private_import;

import->import.is_non_recurse = is_non_recursive;
vec_add(unit->imports, import);
DEBUG_LOG("Added import %s", path->module);
return true;
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/parse_global.c
Original file line number Diff line number Diff line change
Expand Up @@ -2388,6 +2388,7 @@ static inline bool parse_import(ParseContext *c)
is_not_first = true;
Path *path = parse_module_path(c);
if (!path) return false;
bool is_nonrecurse = try_consume(c, TOKEN_BIT_XOR);
bool private = false;
if (tok_is(c, TOKEN_AT_IDENT))
{
Expand All @@ -2399,7 +2400,7 @@ static inline bool parse_import(ParseContext *c)
private = true;
advance_and_verify(c, TOKEN_AT_IDENT);
}
unit_add_import(c->unit, path, private);
unit_add_import(c->unit, path, private, is_nonrecurse);
if (tok_is(c, TOKEN_COLON) && peek(c) == TOKEN_IDENT)
{
PRINT_ERROR_HERE("'::' was expected here, did you make a mistake?");
Expand Down
1 change: 1 addition & 0 deletions src/compiler/sema_name_resolution.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ static bool decl_is_visible(CompilationUnit *unit, Decl *decl)
{
Module *import_module = import->import.module;
if (import_module == module) return true;
if (import->import.is_non_recurse) continue;
if (module_inclusion_match(import_module, module)) return true;
}
return false;
Expand Down
5 changes: 5 additions & 0 deletions test/test_suite/import/import_nonrecurse.c3
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import std::io^;
fn void main()
{
(void)file::open("test", "r"); // #error: std::io::file::open
}

0 comments on commit 413877b

Please sign in to comment.