motiejus/zig

fork of https://codeberg.org/ziglang/zig
git clone https://git.jakstys.lt/motiejus/zig.git
Log | Tree | Refs | README | LICENSE

commit 903bed931dddc8b3f7ad1fa87e57eca13375dd32 (tree)
parent f598234ee820ca0d57946542a852f193b21d847f
Author: Andreas Reischuck <andreas.reischuck@hicknhack-software.com>
Date:   Mon, 16 May 2022 19:42:08 +0200

report better error for package not found in stage2

Diffstat:
Msrc/Sema.zig | 15+++++++++++++++
Atest/cases/compile_errors/import_of_missing_package.zig | 10++++++++++
2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/src/Sema.zig b/src/Sema.zig @@ -9839,6 +9839,21 @@ fn zirImport(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Air. error.ImportOutsidePkgPath => { return sema.fail(block, operand_src, "import of file outside package path: '{s}'", .{operand}); }, + error.PackageNotFound => { + const cur_pkg = block.getFileScope().pkg; + const parent = if (cur_pkg == sema.mod.main_pkg or cur_pkg == sema.mod.root_pkg) + "root" + else if (cur_pkg.parent) |parent| blk: { + var it = parent.table.iterator(); + while (it.next()) |pkg| { + if (pkg.value_ptr.* == cur_pkg) { + break :blk pkg.key_ptr.*; + } + } + unreachable; + } else unreachable; + return sema.fail(block, operand_src, "no package named '{s}' available within package '{s}'", .{ operand, parent }); + }, else => { // TODO: these errors are file system errors; make sure an update() will // retry this and not cache the file system error, which may be transient. diff --git a/test/cases/compile_errors/import_of_missing_package.zig b/test/cases/compile_errors/import_of_missing_package.zig @@ -0,0 +1,10 @@ +const foo = @import("foo"); +comptime { + _ = foo; +} + +// error +// backend=stage2 +// target=native +// +// :1:21: error: no package named 'foo' available within package 'root'