authorgravatar for andreas.reischuck@hicknhack-software.comAndreas Reischuck <andreas.reischuck@hicknhack-software.com> 2022-05-16 19:42:08+02:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-07-24 11:55:37+03:00
log903bed931dddc8b3f7ad1fa87e57eca13375dd32
tree1a8e2736fb3197a5628e0f7742f6d68cdb8dd3b6
parentf598234ee820ca0d57946542a852f193b21d847f

report better error for package not found in stage2


2 files changed, 25 insertions(+), 0 deletions(-)

src/Sema.zig+15
......@@ -9839,6 +9839,21 @@ fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air.
98399839 error.ImportOutsidePkgPath => {
98409840 return sema.fail(block, operand_src, "import of file outside package path: '{s}'", .{operand});
98419841 },
9842 error.PackageNotFound => {
9843 const cur_pkg = block.getFileScope().pkg;
9844 const parent = if (cur_pkg == sema.mod.main_pkg or cur_pkg == sema.mod.root_pkg)
9845 "root"
9846 else if (cur_pkg.parent) |parent| blk: {
9847 var it = parent.table.iterator();
9848 while (it.next()) |pkg| {
9849 if (pkg.value_ptr.* == cur_pkg) {
9850 break :blk pkg.key_ptr.*;
9851 }
9852 }
9853 unreachable;
9854 } else unreachable;
9855 return sema.fail(block, operand_src, "no package named '{s}' available within package '{s}'", .{ operand, parent });
9856 },
98429857 else => {
98439858 // TODO: these errors are file system errors; make sure an update() will
98449859 // retry this and not cache the file system error, which may be transient.
test/cases/compile_errors/import_of_missing_package.zig created+10
......@@ -0,0 +1,10 @@
1const foo = @import("foo");
2comptime {
3 _ = foo;
4}
5
6// error
7// backend=stage2
8// target=native
9//
10// :1:21: error: no package named 'foo' available within package 'root'