authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-06-22 16:11:02-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-06-23 10:44:46-07:00
log150515f44db9cecbda31d579861dc6f6080c2f75
tree859145a3479f7e9880269b2ef945bfce3043ccf3
parent6fb45807abab49982c12b71112e9acb39cf94270

stage2: slightly improve error reporting for missing imports

There is now a distinction between `@import` with a .zig extension and without. Without a .zig extension it assumes it is a package name, and returns error.PackageNotFound if not mapped into the package table.

3 files changed, 20 insertions(+), 5 deletions(-)

src/Compilation.zig+17-4
......@@ -2319,6 +2319,9 @@ fn workerAstGenFile(
23192319 break :blk mod.importFile(file, import_path) catch continue;
23202320 };
23212321 if (import_result.is_new) {
2322 log.debug("AstGen of {s} has import '{s}'; queuing AstGen of {s}", .{
2323 file.sub_file_path, import_path, import_result.file.sub_file_path,
2324 });
23222325 wg.start();
23232326 comp.thread_pool.spawn(workerAstGenFile, .{
23242327 comp, import_result.file, prog_node, wg,
......@@ -2540,13 +2543,23 @@ fn reportRetryableAstGenError(
25402543
25412544 file.status = .retryable_failure;
25422545
2543 const err_msg = try Module.ErrorMsg.create(gpa, .{
2546 const src_loc: Module.SrcLoc = .{
25442547 .file_scope = file,
25452548 .parent_decl_node = 0,
25462549 .lazy = .entire_file,
2547 }, "unable to load {s}: {s}", .{
2548 file.sub_file_path, @errorName(err),
2549 });
2550 };
2551
2552 const err_msg = if (file.pkg.root_src_directory.path) |dir_path|
2553 try Module.ErrorMsg.create(
2554 gpa,
2555 src_loc,
2556 "unable to load {s}" ++ std.fs.path.sep_str ++ "{s}: {s}",
2557 .{ dir_path, file.sub_file_path, @errorName(err) },
2558 )
2559 else
2560 try Module.ErrorMsg.create(gpa, src_loc, "unable to load {s}: {s}", .{
2561 file.sub_file_path, @errorName(err),
2562 });
25502563 errdefer err_msg.destroy(gpa);
25512564
25522565 {
src/Module.zig+3
......@@ -3185,6 +3185,9 @@ pub fn importFile(
31853185 if (cur_file.pkg.table.get(import_string)) |pkg| {
31863186 return mod.importPkg(pkg);
31873187 }
3188 if (!mem.endsWith(u8, import_string, ".zig")) {
3189 return error.PackageNotFound;
3190 }
31883191 const gpa = mod.gpa;
31893192
31903193 // The resolved path is used as the key in the import table, to detect if
src/codegen/x86_64.zig-1
......@@ -4,7 +4,6 @@ const mem = std.mem;
44const assert = std.debug.assert;
55const ArrayList = std.ArrayList;
66const Allocator = std.mem.Allocator;
7const Type = @import("../Type.zig");
87const DW = std.dwarf;
98
109// zig fmt: off