diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-05-17 19:11:11 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-05-17 19:11:11 -0700 |
| commit | 1d808d0dd20326dbdb0478f2a2f43f0b9ebb557a (patch) | |
| tree | ebb6072e5533949e8c7273d4f57d69b861ddf1fd /src/Module.zig | |
| parent | 67f5a28257b50e72750f51a03d6ce9ee27ad1439 (diff) | |
| download | zig-1d808d0dd20326dbdb0478f2a2f43f0b9ebb557a.tar.gz zig-1d808d0dd20326dbdb0478f2a2f43f0b9ebb557a.zip | |
stage2: fix crash in switch compile error
when the AST for the switch has never been loaded
Diffstat (limited to 'src/Module.zig')
| -rw-r--r-- | src/Module.zig | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/Module.zig b/src/Module.zig index e659f4ed47..39caa24d75 100644 --- a/src/Module.zig +++ b/src/Module.zig @@ -4419,13 +4419,20 @@ pub const SwitchProngSrc = union(enum) { /// the LazySrcLoc in order to emit a compile error. pub fn resolve( prong_src: SwitchProngSrc, + gpa: *Allocator, decl: *Decl, switch_node_offset: i32, range_expand: RangeExpand, ) LazySrcLoc { @setCold(true); + const tree = decl.namespace.file_scope.getTree(gpa) catch |err| { + // In this case we emit a warning + a less precise source location. + log.warn("unable to load {s}: {s}", .{ + decl.namespace.file_scope.sub_file_path, @errorName(err), + }); + return LazySrcLoc{ .node_offset = 0}; + }; const switch_node = decl.relativeToNodeIndex(switch_node_offset); - const tree = decl.namespace.file_scope.tree; const main_tokens = tree.nodes.items(.main_token); const node_datas = tree.nodes.items(.data); const node_tags = tree.nodes.items(.tag); |
