Skip to content

[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

Merged
merged 3 commits into from
Jan 8, 2019

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Jan 7, 2019

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.

@xedin xedin requested a review from DougGregor January 7, 2019 19:37
@xedin
Copy link
Contributor Author

xedin commented Jan 7, 2019

@swift-ci please smoke test

@xedin
Copy link
Contributor Author

xedin commented Jan 8, 2019

@swift-ci please smoke test

xedin added 2 commits January 8, 2019 12:06
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.
@xedin xedin force-pushed the diagnose-subscript-misuse-via-fixes branch from fcb5dd9 to 506b755 Compare January 8, 2019 20:07
@xedin
Copy link
Contributor Author

xedin commented Jan 8, 2019

@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.
@xedin xedin force-pushed the diagnose-subscript-misuse-via-fixes branch from 506b755 to 91e97a0 Compare January 8, 2019 20:09
@xedin
Copy link
Contributor Author

xedin commented Jan 8, 2019

@swift-ci please smoke test

@xedin xedin merged commit af34984 into swiftlang:master Jan 8, 2019
_ = 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?}}
Copy link
Contributor

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)'}}
Copy link
Contributor

@jrose-apple jrose-apple Jan 8, 2019

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?

Copy link
Contributor Author

@xedin xedin Jan 8, 2019

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.

Copy link
Contributor

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!

Copy link
Contributor Author

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...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants