-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Modified error message for the issue "Instance member cannot be used on type" #78043
base: main
Are you sure you want to change the base?
Conversation
Now the error message is more specific.
@@ -1578,7 +1578,7 @@ ERROR(member_shadows_global_function,none, | |||
(DeclNameRef, DescriptiveDeclKind, const ValueDecl *, DeclName)) | |||
|
|||
ERROR(instance_member_use_on_type,none, | |||
"instance member %1 cannot be used on type %0; " | |||
"%1 non-static instance member cannot be called without an instance of type %0; " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not all members are called, though. “Referenced” might be better
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
made the required changes. Kindly review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that the error in question is could_not_use_instance_member_on_type
, not this one. They are similar, but this one targets a slightly different case: S.instanceMember
.
I think we should explore the addition of a new tailored message for accesses on implicit self rather than trying to make the current one fit all targeted cases. This is what I proposed last time.
As far as I can tell, the message targets 2 cases:
struct S {
func instanceF() {}
}
// 1.
let m = S.self
m.instanceF()
// 2.
extension S {
static func staticF() {
instanceF()
}
}
The GitHub issue calls out case 2.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am unsure about how to proceed about the changes, could you please guide me a bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the message ID to search for the place where it is emitted. Take time to read through and examine the code around the emission site(s). Try to understand what is going on: which case is being handled, how the case is identified, what information is available about the diagnosed expression, and how you could use this data to form a condition for case 2 if we have not already.
If you prefer Xcode, adding some breakpoints and running the compiler with a Swift file containing the test case can be very helpful. Refer to this piece of documentation for LLDB advice.
If you have questions along the way, you are welcome to post them in the PR 🙂
changed "called" to referenced
I would like to encourage reviewers to read through a previous attempt at this: #63301. |
PR for #62909
Now the error message is more specific. Kindly review.