mirror of
https://github.com/ziglang/zig.git
synced 2024-11-27 07:32:44 +00:00
stage2: improve error message for missing member in file root struct
* the root struct decl name is fully qualified this prevents error messages containing 'main.main' * avoid declared here note when file struct is missing a member It always points at the start of the file which might contain another container misleading the user.
This commit is contained in:
parent
409cf4aeb8
commit
b3c6d774d2
@ -4435,6 +4435,7 @@ pub fn semaFile(mod: *Module, file: *File) SemaError!void {
|
||||
new_decl.alive = true; // This Decl corresponds to a File and is therefore always alive.
|
||||
new_decl.analysis = .in_progress;
|
||||
new_decl.generation = mod.generation;
|
||||
new_decl.name_fully_qualified = true;
|
||||
|
||||
if (file.status == .success_zir) {
|
||||
assert(file.zir_loaded);
|
||||
|
@ -4353,6 +4353,11 @@ fn failWithBadMemberAccess(
|
||||
.Enum => "enum",
|
||||
else => unreachable,
|
||||
};
|
||||
if (sema.mod.declIsRoot(agg_ty.getOwnerDecl())) {
|
||||
return sema.fail(block, field_src, "root struct of file '{}' has no member named '{s}'", .{
|
||||
agg_ty.fmt(sema.mod), field_name,
|
||||
});
|
||||
}
|
||||
const msg = msg: {
|
||||
const msg = try sema.errMsg(block, field_src, "{s} '{}' has no member named '{s}'", .{
|
||||
kw_name, agg_ty.fmt(sema.mod), field_name,
|
||||
|
@ -2,5 +2,4 @@
|
||||
// output_mode=Exe
|
||||
// target=aarch64-macos
|
||||
//
|
||||
// :109:9: error: struct 'tmp.tmp' has no member named 'main'
|
||||
// :7:1: note: struct declared here
|
||||
// :109:9: error: root struct of file 'tmp' has no member named 'main'
|
||||
|
@ -5,5 +5,4 @@ export fn entry() usize { return @sizeOf(@TypeOf(x)); }
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// :1:29: error: struct 'builtin.builtin' has no member named 'bogus'
|
||||
// :1:1: note: struct declared here
|
||||
// :1:29: error: root struct of file 'builtin' has no member named 'bogus'
|
||||
|
@ -7,5 +7,5 @@ export fn entry() void {
|
||||
// backend=stage2
|
||||
// target=native
|
||||
//
|
||||
// :2:27: error: expected type 'u32', found 'tmp.tmp'
|
||||
// :2:27: error: expected type 'u32', found 'tmp'
|
||||
// :1:1: note: struct declared here
|
||||
|
@ -2,5 +2,4 @@
|
||||
// output_mode=Exe
|
||||
// target=x86_64-linux
|
||||
//
|
||||
// :109:9: error: struct 'tmp.tmp' has no member named 'main'
|
||||
// :7:1: note: struct declared here
|
||||
// :109:9: error: root struct of file 'tmp' has no member named 'main'
|
||||
|
@ -2,5 +2,4 @@
|
||||
// output_mode=Exe
|
||||
// target=x86_64-macos
|
||||
//
|
||||
// :109:9: error: struct 'tmp.tmp' has no member named 'main'
|
||||
// :7:1: note: struct declared here
|
||||
// :109:9: error: root struct of file 'tmp' has no member named 'main'
|
||||
|
@ -2,5 +2,4 @@
|
||||
// output_mode=Exe
|
||||
// target=x86_64-windows
|
||||
//
|
||||
// :130:9: error: struct 'tmp.tmp' has no member named 'main'
|
||||
// :7:1: note: struct declared here
|
||||
// :130:9: error: root struct of file 'tmp' has no member named 'main'
|
||||
|
Loading…
Reference in New Issue
Block a user