diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-05-11 17:44:19 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-05-11 17:44:19 -0700 |
| commit | 7873e4f5889f9e1b4d5b5f62d7701d7914b64ab1 (patch) | |
| tree | 8ee9468285c059f3e5c09ba26d5ca99ba4eadd03 /src/Module.zig | |
| parent | cbbc7cc8b1edeeae1715248a5d13304027698367 (diff) | |
| download | zig-7873e4f5889f9e1b4d5b5f62d7701d7914b64ab1.tar.gz zig-7873e4f5889f9e1b4d5b5f62d7701d7914b64ab1.zip | |
stage2: lookupIdentifier can return error.AnalysisFailed
This avoids causing false positive compile errors when, for example, a
file had ZIR errors, and then code tried to look up a public decl from
the failed file.
Diffstat (limited to 'src/Module.zig')
| -rw-r--r-- | src/Module.zig | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/src/Module.zig b/src/Module.zig index 8789367aa4..dcadb8e23e 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -3096,7 +3096,6 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool { try mod.analyzeExport(&block_scope.base, export_src, mem.spanZ(decl.name), decl); } - return type_changed; } } @@ -3881,10 +3880,14 @@ pub fn getNextAnonNameIndex(mod: *Module) usize { /// This looks up a bare identifier in the given scope. This will walk up the tree of namespaces /// in scope and check each one for the identifier. /// TODO emit a compile error if more than one decl would be matched. -pub fn lookupIdentifier(mod: *Module, scope: *Scope, ident_name: []const u8) ?*Decl { +pub fn lookupIdentifier( + mod: *Module, + scope: *Scope, + ident_name: []const u8, +) error{AnalysisFail}!?*Decl { var namespace = scope.namespace(); while (true) { - if (mod.lookupInNamespace(namespace, ident_name, false)) |decl| { + if (try mod.lookupInNamespace(namespace, ident_name, false)) |decl| { return decl; } namespace = namespace.parent orelse break; @@ -3899,7 +3902,12 @@ pub fn lookupInNamespace( namespace: *Scope.Namespace, ident_name: []const u8, only_pub_usingnamespaces: bool, -) ?*Decl { +) error{AnalysisFail}!?*Decl { + const owner_decl = namespace.getDecl(); + if (owner_decl.analysis == .file_failure) { + return error.AnalysisFail; + } + // TODO the decl doing the looking up needs to create a decl dependency // TODO implement usingnamespace if (namespace.decls.get(ident_name)) |decl| { |
