fix: Add error notes for method calls on double pointers (#20686)

This commit is contained in:
Will Lillis 2024-07-21 03:03:23 -04:00 committed by GitHub
parent 93c546c8c9
commit 9b292c0949
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 0 deletions

View File

@ -28023,6 +28023,10 @@ fn fieldCallBind(
if (concrete_ty.zigTypeTag(mod) == .ErrorUnion) {
try sema.errNote(src, msg, "consider using 'try', 'catch', or 'if'", .{});
}
if (is_double_ptr) {
try sema.errNote(src, msg, "method invocation only supports up to one level of implicit pointer dereferencing", .{});
try sema.errNote(src, msg, "use '.*' to dereference pointer", .{});
}
break :msg msg;
};
return sema.failWithOwnedErrorMsg(block, msg);

View File

@ -0,0 +1,15 @@
const S = struct {
fn b() void {}
};
export fn entry(a: **S) void {
_ = a.b();
}
// error
// backend=stage2
// target=native
//
// 6:10: error: no field or member function named 'b' in '*tmp.S'
// 6:10: note: method invocation only supports up to one level of implicit pointer dereferencing
// 6:10: note: use '.*' to dereference pointer