-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Diagnostics] Diagnose subscript operator misuse via fixes #21682
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
[Diagnostics] Diagnose subscript operator misuse via fixes #21682
Conversation
@swift-ci please smoke test |
@swift-ci please smoke test |
If there are no members named "subscript" available, let's try to replace it with subscript operator with might be what was intended.
Fix to use subscript operator instead of spelled out name helps to produce a solution, that makes it much easier to diagnose problems precisely and provide proper fix-its, it also helps to diagnose ambiguous cases, and stacks up nicely with other errors.
fcb5dd9
to
506b755
Compare
@swift-ci please smoke test |
…x as a missing member Since the rule is to prioritize names over types, let's diagnose ambiguous solutions containing subscript operator fix as missing member and list possible candidates to use.
506b755
to
91e97a0
Compare
@swift-ci please smoke test |
_ = s1.subscript("hello") | ||
// expected-error@-1 {{value of type 'SubscriptTest1' has no property or method named 'subscript'; did you mean to use the subscript operator?}} {{9-10=}} {{10-19=}} {{19-20=[}} {{27-28=]}} | ||
// expected-error@-1 {{value of type 'SubscriptTest1' has no property or method named 'subscript'; did you mean to use the subscript operator?}} |
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.
Did we lose the fix-its here?
_ = s1.subscript(SubSubClass()) | ||
// expected-error@-1 {{value of type 'SubscriptTest1' has no property or method named 'subscript'; did you mean to use the subscript operator?}} {{9-10=}} {{10-19=}} {{19-20=[}} {{33-34=]}} | ||
_ = s1.subscript(ClassConformingToProtocol()) | ||
// expected-error@-1 {{value of type 'SubscriptTest1' has no property or method named 'subscript'; did you mean to use the subscript operator?}} {{9-10=}} {{10-19=}} {{19-20=[}} {{47-48=]}} | ||
_ = s1.subscript(ClassConformingToRefinedProtocol()) | ||
// expected-error@-1 {{value of type 'SubscriptTest1' has no property or method named 'subscript'; did you mean to use the subscript operator?}} {{9-10=}} {{10-19=}} {{19-20=[}} {{54-55=]}} | ||
_ = s1.subscript(true) | ||
// expected-error@-1 {{value of type 'SubscriptTest1' has no property or method named 'subscript'; did you mean to use the subscript operator?}} | ||
// expected-error@-1 {{cannot invoke 'subscript' with an argument list of type '(Bool)'}} |
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 guess you disagree with me on this? This is one of the ones that's changed for the worse (IMO). Can you get it to use your new wording?
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.
No, I don't really disagree, I'm just going to make it work with re-labeling/re-typing fix. It's going to have both diagnostics for incorrect argument to fix-it about subscript
. It's on my radar, I just need to gradually fix CSDiag mess, because that's what is the biggest barrier here is.
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.
Okay, I'll stop bugging you about this. :-) I definitely think you've been doing great chipping away at CSDiag!
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.
It's okay, no problem! :) Once I convert most of the stuff to use fixes we wouldn't have this ordering problem anymore, but for a bit some of the diagnostics might be in reverse order to what they used to be before, because it would fall into CSDiag first and then diagnose with a fix...
Fix to use subscript operator instead of spelled out name helps
to produce a solution, that makes it much easier to diagnose
problems precisely and provide proper fix-its, it also helps to
diagnose ambiguous cases, and stacks up nicely with other errors.