mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
report better error for package not found in stage2
This commit is contained in:
parent
f598234ee8
commit
903bed931d
15
src/Sema.zig
15
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.
|
||||
|
||||
10
test/cases/compile_errors/import_of_missing_package.zig
Normal file
10
test/cases/compile_errors/import_of_missing_package.zig
Normal file
@ -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'
|
||||
Loading…
x
Reference in New Issue
Block a user