-
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
Improve error message on attempt to use instance member in static context #63301
base: main
Are you sure you want to change the base?
Improve error message on attempt to use instance member in static context #63301
Conversation
@@ -1335,7 +1335,7 @@ ERROR(member_shadows_global_function,none, | |||
(DeclNameRef, DescriptiveDeclKind, DescriptiveDeclKind, DeclName, DeclName)) | |||
|
|||
ERROR(instance_member_use_on_type,none, | |||
"instance member %1 cannot be used on type %0; " | |||
"instance member %1 of type %0 cannot be used in static context; " |
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 don't think that "in static context" brings any clarify because everybody has a different idea what "static context" means, but I'm biased. @hborla WDYT?
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’m probably biased too, but I read this as "you cannot use this at all in a static function". Regrettably, the best alternative I can currently think of is instance member cannot be used on type object
.
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.
However, maybe it does make sense to say "static context" specifically when self.
is implicit, keep the current wording for T.
, and say "metatype" for meta.
.
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.
"you cannot use this at all in a static function".
This is exactly what I'm afraid of happening.
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.
Guys, how should we proceed with this fix?
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.
The primary goal is to tailor the message for implicit accesses on self
specifically. The current message reads well when applied to an explicit access on a type identifier as in T.member()
. As for how exactly we want to tailor it, we need to come up with a better idea than what was voiced in the issue.
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.
Maybe a good start would be to limit this diagnostic to situations when self.
is implicit (that's what "in static context" means for a lot of people IMHO).
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.
Putting in my two cents: instance member %1 cannot be used on static 'self'
9f895aa
to
41b8173
Compare
That alternative error message, Perhaps a more accurate alternative error message could be: |
Not really. In a static context,
I think this message has the same problem as the synonymous |
What @tysun said really nails it down for me. What do others think? Instance member %1 cannot be accessed directly from a static method of the same type |
Resolves #62909