diff options
| author | Veikka Tuominen <git@vexu.eu> | 2022-11-09 18:01:34 +0200 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-11-11 17:59:53 +0200 |
| commit | 9b832e7f530833de93857444a86e34c8d99e4755 (patch) | |
| tree | 82f844a4f4552d652d5c32ac3d12e718b7d420fe /src | |
| parent | 25c850642190bf9939790b872a3657410ec4d19f (diff) | |
| download | zig-9b832e7f530833de93857444a86e34c8d99e4755.tar.gz zig-9b832e7f530833de93857444a86e34c8d99e4755.zip | |
Sema: make check for namespace lookup of private declarations more strict
Previously sema only checked that the private declaration was in the same
file as the lookup but now it also checks that the namespace where
the decl was included from was also in the same file.
Closes #13077
Diffstat (limited to 'src')
| -rw-r--r-- | src/Sema.zig | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index 0ca92fb649..b93a892dcc 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -5658,14 +5658,14 @@ fn lookupInNamespace( const src_file = block.namespace.file_scope; const gpa = sema.gpa; - var checked_namespaces: std.AutoArrayHashMapUnmanaged(*Namespace, void) = .{}; + var checked_namespaces: std.AutoArrayHashMapUnmanaged(*Namespace, bool) = .{}; defer checked_namespaces.deinit(gpa); // Keep track of name conflicts for error notes. var candidates: std.ArrayListUnmanaged(Decl.Index) = .{}; defer candidates.deinit(gpa); - try checked_namespaces.put(gpa, namespace, {}); + try checked_namespaces.put(gpa, namespace, namespace.file_scope == src_file); var check_i: usize = 0; while (check_i < checked_namespaces.count()) : (check_i += 1) { @@ -5674,7 +5674,7 @@ fn lookupInNamespace( // Skip decls which are not marked pub, which are in a different // file than the `a.b`/`@hasDecl` syntax. const decl = mod.declPtr(decl_index); - if (decl.is_pub or src_file == decl.getFileScope()) { + if (decl.is_pub or (src_file == decl.getFileScope() and checked_namespaces.values()[check_i])) { try candidates.append(gpa, decl_index); } } @@ -5693,7 +5693,7 @@ fn lookupInNamespace( try sema.ensureDeclAnalyzed(sub_usingnamespace_decl_index); const ns_ty = sub_usingnamespace_decl.val.castTag(.ty).?.data; const sub_ns = ns_ty.getNamespace().?; - try checked_namespaces.put(gpa, sub_ns, {}); + try checked_namespaces.put(gpa, sub_ns, src_file == sub_usingnamespace_decl.getFileScope()); } } |
