Skip to content

[CSSimplify] Fix matchDeepEqualityTypes to allow fixing of optionals #81936

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

Conversation

xedin
Copy link
Contributor

@xedin xedin commented Jun 3, 2025

Attempting to propagate generic argument failures up is not always
reliable, matchDeepEqualityTypes should avoid using TMF_ApplyingFix
while dealing with optionals and instead let repairFailures decide
whether to use generic arguments mismatch fix to a more general one.

GenericArgument handling is updated to:

  • Produce a tailored fix for a mismatch in tuple element position
  • Produce a tailored fixes in situations where optional object type is not a class and matched against AnyObject
  • Increase impact if mismatch is contextual (to help prefer a fix at a better location)

Resolves: #81023
Resolves: rdar://149843877

xedin added 2 commits June 2, 2025 17:39
…ch is contextual

If generic arguments mismatch ends up being recorded on the result
of the chain or `try` expression it means that there is a contextual
conversion mismatch.

For optional conversions the solver currently generates a disjunction
with two choices - bind and optional-to-optional conversion which is
anchored on the contextual expression. If we can get a fix recorded
there that would result in a better diagnostic. It's only possible
for optional-to-optional choice because it doesn't bind the
variable immediately, so we need to downgrade direct fixes to prevent
`bind` choice from considered better.
xedin added 3 commits June 3, 2025 00:48
Attempting to propagate generic argument failures up is not always
reliable, `matchDeepEqualityTypes` should avoid using `TMF_ApplyingFix`
while dealing with optionals and instead let `repairFailures` decide
whether to use generic arguments mismatch fix to a more general one.
…ches

- Mismatch in tuple element position should reference whole tuple
  with a note for mismatch position;
- Situations where optional object type is not a class but matched
  against `AnyObject` have a tailored fix.
@xedin xedin force-pushed the improve-optional-wrappedValue-mismatch-diagnostics branch from 07868df to 4132aa0 Compare June 3, 2025 07:49
@xedin
Copy link
Contributor Author

xedin commented Jun 3, 2025

@swift-ci please test

@xedin xedin merged commit b189b8a into swiftlang:main Jun 3, 2025
5 checks passed
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.

Type of expression is ambiguous without a type annotation when using Combine publisher
2 participants