-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Sema] Score non-settable overload choices higher in RValueToLValue fix #74243
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
Conversation
lib/Sema/CSSimplify.cpp
Outdated
if (auto decl = overload->choice.getDeclOrNull()) { | ||
if (auto VD = dyn_cast<VarDecl>(decl)) { | ||
if (!VD->isSettableInSwift(DC)) { | ||
impact += 10; |
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 think this might be too dramatic of an increase, we just need this to be slightly higher then default impact, increase it by too much and it would start competing with other solutions just like what you have in tests where count
is a method and a property.
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.
Yep! I had gotten the mistaken impression that the impact was local to the specific choice location. Changed to just += 1
.
ef7300a
to
909553f
Compare
@swift-ci Please smoke test. |
lib/Sema/CSSimplify.cpp
Outdated
|
||
// An overload choice that isn't settable is least interesting for diagnosis. | ||
if (auto overload = findSelectedOverloadFor(getCalleeLocator(fix->getLocator()))) { | ||
if (auto decl = overload->choice.getDeclOrNull()) { |
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.
All of the nested conditionals could be simplified down to:
if (auto *var = dyn_cast_or_null<VarDecl>(overload->choice.getDeclOrNull())) {
impact += !var->isSettableInSwift(DC) ? 1 : 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.
Thanks, done!
…agnoses from better choices.
909553f
to
843ce58
Compare
@swift-ci Please smoke test. |
With multiple overload choices, TreatRValueAsLValue used to just pick the first solution. We get better diagnostics if we pick a solution where the chosen VarDecl is settable. So make the impact of fixing non-settable overload choices higher, so we get a settable overload, if one exists.
I.e. if you conform to two protocols with same-named property, one of which is {get} and the other is {get set} and both possibilities end up with the same fix in the same location, it isn't much help to use the "it's a get-only property" choice.
Resolves #46265
Removed the previous commit and force pushed my branch before committing the new changes, and hadn't realized that makes GitHub automatically close the PR when there's (briefly) no changes. Oops. So here's a new PR.