Skip to content

[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

Merged
merged 1 commit into from
Jun 15, 2024

Conversation

gregomni
Copy link
Contributor

@gregomni gregomni commented Jun 9, 2024

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.

@gregomni
Copy link
Contributor Author

gregomni commented Jun 9, 2024

@xedin Thanks for the suggestion! Didn't realize the impact scoring on fixes existed until you said.

@swift-ci Please smoke test.

if (auto decl = overload->choice.getDeclOrNull()) {
if (auto VD = dyn_cast<VarDecl>(decl)) {
if (!VD->isSettableInSwift(DC)) {
impact += 10;
Copy link
Contributor

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.

Copy link
Contributor Author

@gregomni gregomni Jun 12, 2024

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.

@gregomni gregomni force-pushed the rvalue-ambiguous branch 2 times, most recently from ef7300a to 909553f Compare June 12, 2024 03:07
@gregomni
Copy link
Contributor Author

@swift-ci Please smoke test.


// 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()) {
Copy link
Contributor

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;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, done!

@gregomni
Copy link
Contributor Author

@swift-ci Please smoke test.

@gregomni gregomni merged commit fb2d667 into swiftlang:main Jun 15, 2024
3 checks passed
@gregomni gregomni deleted the rvalue-ambiguous branch June 16, 2024 00:08
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.

[SR-3680] Incorrect error about readonly property in protocol extension that conforms to another protocol
2 participants