| author | |
| committer | |
| log | 7873e4f5889f9e1b4d5b5f62d7701d7914b64ab1 |
| tree | 8ee9468285c059f3e5c09ba26d5ca99ba4eadd03 |
| parent | cbbc7cc8b1edeeae1715248a5d13304027698367 |
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.2 files changed, 15 insertions(+), 7 deletions(-)
src/Module.zig+12-4| ... | @@ -3096,7 +3096,6 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool { | ... | @@ -3096,7 +3096,6 @@ fn semaDecl(mod: *Module, decl: *Decl) !bool { |
| 3096 | try mod.analyzeExport(&block_scope.base, export_src, mem.spanZ(decl.name), decl); | 3096 | try mod.analyzeExport(&block_scope.base, export_src, mem.spanZ(decl.name), decl); |
| 3097 | } | 3097 | } |
| 3098 | 3098 | ||
| 3099 | |||
| 3100 | return type_changed; | 3099 | return type_changed; |
| 3101 | } | 3100 | } |
| 3102 | } | 3101 | } |
| ... | @@ -3881,10 +3880,14 @@ pub fn getNextAnonNameIndex(mod: *Module) usize { | ... | @@ -3881,10 +3880,14 @@ pub fn getNextAnonNameIndex(mod: *Module) usize { |
| 3881 | /// This looks up a bare identifier in the given scope. This will walk up the tree of namespaces | 3880 | /// This looks up a bare identifier in the given scope. This will walk up the tree of namespaces |
| 3882 | /// in scope and check each one for the identifier. | 3881 | /// in scope and check each one for the identifier. |
| 3883 | /// TODO emit a compile error if more than one decl would be matched. | 3882 | /// TODO emit a compile error if more than one decl would be matched. |
| 3884 | pub fn lookupIdentifier(mod: *Module, scope: *Scope, ident_name: []const u8) ?*Decl { | 3883 | pub fn lookupIdentifier( |
| 3884 | mod: *Module, | ||
| 3885 | scope: *Scope, | ||
| 3886 | ident_name: []const u8, | ||
| 3887 | ) error{AnalysisFail}!?*Decl { | ||
| 3885 | var namespace = scope.namespace(); | 3888 | var namespace = scope.namespace(); |
| 3886 | while (true) { | 3889 | while (true) { |
| 3887 | if (mod.lookupInNamespace(namespace, ident_name, false)) |decl| { | 3890 | if (try mod.lookupInNamespace(namespace, ident_name, false)) |decl| { |
| 3888 | return decl; | 3891 | return decl; |
| 3889 | } | 3892 | } |
| 3890 | namespace = namespace.parent orelse break; | 3893 | namespace = namespace.parent orelse break; |
| ... | @@ -3899,7 +3902,12 @@ pub fn lookupInNamespace( | ... | @@ -3899,7 +3902,12 @@ pub fn lookupInNamespace( |
| 3899 | namespace: *Scope.Namespace, | 3902 | namespace: *Scope.Namespace, |
| 3900 | ident_name: []const u8, | 3903 | ident_name: []const u8, |
| 3901 | only_pub_usingnamespaces: bool, | 3904 | only_pub_usingnamespaces: bool, |
| 3902 | ) ?*Decl { | 3905 | ) error{AnalysisFail}!?*Decl { |
| 3906 | const owner_decl = namespace.getDecl(); | ||
| 3907 | if (owner_decl.analysis == .file_failure) { | ||
| 3908 | return error.AnalysisFail; | ||
| 3909 | } | ||
| 3910 | |||
| 3903 | // TODO the decl doing the looking up needs to create a decl dependency | 3911 | // TODO the decl doing the looking up needs to create a decl dependency |
| 3904 | // TODO implement usingnamespace | 3912 | // TODO implement usingnamespace |
| 3905 | if (namespace.decls.get(ident_name)) |decl| { | 3913 | if (namespace.decls.get(ident_name)) |decl| { |
src/Sema.zig+3-3| ... | @@ -2044,7 +2044,7 @@ fn zirDeclVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError | ... | @@ -2044,7 +2044,7 @@ fn zirDeclVal(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError |
| 2044 | 2044 | ||
| 2045 | fn lookupIdentifier(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, name: []const u8) !*Decl { | 2045 | fn lookupIdentifier(sema: *Sema, block: *Scope.Block, src: LazySrcLoc, name: []const u8) !*Decl { |
| 2046 | const mod = sema.mod; | 2046 | const mod = sema.mod; |
| 2047 | const decl = mod.lookupIdentifier(&sema.namespace.base, name) orelse { | 2047 | const decl = (try mod.lookupIdentifier(&sema.namespace.base, name)) orelse { |
| 2048 | // TODO insert a "dependency on the non-existence of a decl" here to make this | 2048 | // TODO insert a "dependency on the non-existence of a decl" here to make this |
| 2049 | // compile error go away when the decl is introduced. This data should be in a global | 2049 | // compile error go away when the decl is introduced. This data should be in a global |
| 2050 | // sparse map since it is only relevant when a compile error occurs. | 2050 | // sparse map since it is only relevant when a compile error occurs. |
| ... | @@ -4359,7 +4359,7 @@ fn zirHasDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError | ... | @@ -4359,7 +4359,7 @@ fn zirHasDecl(sema: *Sema, block: *Scope.Block, inst: Zir.Inst.Index) InnerError |
| 4359 | "expected struct, enum, union, or opaque, found '{}'", | 4359 | "expected struct, enum, union, or opaque, found '{}'", |
| 4360 | .{container_type}, | 4360 | .{container_type}, |
| 4361 | ); | 4361 | ); |
| 4362 | if (mod.lookupInNamespace(namespace, decl_name, true)) |decl| { | 4362 | if (try mod.lookupInNamespace(namespace, decl_name, true)) |decl| { |
| 4363 | if (decl.is_pub or decl.namespace.file_scope == block.base.namespace().file_scope) { | 4363 | if (decl.is_pub or decl.namespace.file_scope == block.base.namespace().file_scope) { |
| 4364 | return mod.constBool(arena, src, true); | 4364 | return mod.constBool(arena, src, true); |
| 4365 | } | 4365 | } |
| ... | @@ -6279,7 +6279,7 @@ fn analyzeNamespaceLookup( | ... | @@ -6279,7 +6279,7 @@ fn analyzeNamespaceLookup( |
| 6279 | ) InnerError!?*Inst { | 6279 | ) InnerError!?*Inst { |
| 6280 | const mod = sema.mod; | 6280 | const mod = sema.mod; |
| 6281 | const gpa = sema.gpa; | 6281 | const gpa = sema.gpa; |
| 6282 | if (mod.lookupInNamespace(namespace, decl_name, true)) |decl| { | 6282 | if (try mod.lookupInNamespace(namespace, decl_name, true)) |decl| { |
| 6283 | if (!decl.is_pub and decl.namespace.file_scope != block.getFileScope()) { | 6283 | if (!decl.is_pub and decl.namespace.file_scope != block.getFileScope()) { |
| 6284 | const msg = msg: { | 6284 | const msg = msg: { |
| 6285 | const msg = try mod.errMsg(&block.base, src, "'{s}' is not marked 'pub'", .{ | 6285 | const msg = try mod.errMsg(&block.base, src, "'{s}' is not marked 'pub'", .{ |