Skip to content

[ConstraintSystem] Increase score only if members found on Optional #35381

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
Jan 14, 2021

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Jan 12, 2021

… and its unwrapped type

Unresolved member lookup is allowed to perform implicit optional
unwrap of a base type to find members. Previously if there were
any members directly on Optional, lookup would stop there. But
since SR-13815 it became possible for solver to attempt members
found on unwrapped type even if there are viable ones on
Optional as well.

New score kind has been introduced to guard against possible ambiguities
with new scheme - SK_UnresolvedMemberViaOptional. It's used very
time member found via base type unwrap is attempted. Unfortunately,
doing so can lead to behavior changes in existing code because it's
possible that base was wrapped into optional implicitly based on
context e.g. unresolved member passed in as an argument to a parameter
of optional type.

To fix situations like that, SK_UnresolvedMemberViaOptional should
only be increased if there is a mix of members to attempt - both directly
on Optional and on unwrapped type, in all other cases score should stay
the same because there could be no ambiguity.

Resolves: rdar://73027153

@xedin xedin requested a review from hborla January 12, 2021 22:20
@xedin
Copy link
Contributor Author

xedin commented Jan 12, 2021

@swift-ci please smoke test

@xedin
Copy link
Contributor Author

xedin commented Jan 12, 2021

@swift-ci please test source compatibility

… and its unwrapped type

Unresolved member lookup is allowed to perform implicit optional
unwrap of a base type to find members. Previously if there were
any members directly on `Optional`, lookup would stop there. But
since SR-13815 it became possible for solver to attempt members
found on unwrapped type even if there are viable ones on
`Optional` as well.

New score kind has been introduced to guard against possible ambiguities
with new scheme - `SK_UnresolvedMemberViaOptional`. It's used very
time member found via base type unwrap is attempted. Unfortunately,
doing so can lead to behavior changes in existing code because it's
possible that base was wrapped into optional implicitly based on
context e.g. unresolved member passed in as an argument to a parameter
of optional type.

To fix situations like that, `SK_UnresolvedMemberViaOptional` should
only be increased if there is a mix of members to attempt - both directly
on `Optional` and on unwrapped type, in all other cases score should stay
the same because there could be no ambiguity.

Resolves: rdar://73027153
@xedin
Copy link
Contributor Author

xedin commented Jan 13, 2021

@swift-ci please smoke test

@xedin
Copy link
Contributor Author

xedin commented Jan 14, 2021

@swift-ci please smoke test Linux platform

@xedin
Copy link
Contributor Author

xedin commented Jan 14, 2021

@swift-ci please smoke test Windows platform

@xedin
Copy link
Contributor Author

xedin commented Jan 14, 2021

@swift-ci please test Linux platform

@xedin
Copy link
Contributor Author

xedin commented Jan 14, 2021

@swift-ci please smoke test Linux platform

@xedin xedin merged commit 7fada0a into swiftlang:main Jan 14, 2021
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