-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[Sema] Constrain result type of expressions in optional pattern bindings #18188
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
[Sema] Constrain result type of expressions in optional pattern bindings #18188
Conversation
lib/Sema/TypeCheckConstraints.cpp
Outdated
Type convertTo = convertType.getType(); | ||
if (options.contains(TypeCheckExprFlags::ExpressionTypeMustBeOptional)) { | ||
assert(!convertTo && "convertType and type check options conflict"); | ||
Type var = cs.createTypeVariable(cs.getConstraintLocator(expr)); |
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.
It would be great if you could add a new ConstraintLocator::PathElementKind
for this, so it would be possible to identify such "contextual hints" based on their locators.
6fb68bc
to
9e5d9c3
Compare
lib/Sema/ConstraintLocator.h
Outdated
DynamicLookupResult, | ||
/// \brief The desired convert type passed in to the constraint system. | ||
ConvertType, |
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.
Thank you! Just a nit: how about ContextualType
instead?
@xedin Sure thing! |
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.
LGTM!
@swift-ci Please smoke test and merge. |
Missed a spot where the new locator path info needs to be stripped back off for diagnosis. @swift-ci Please smoke test and merge. |
@swift-ci Please smoke test. |
@swift-ci please test source compatibility |
17f2725
to
d70702c
Compare
so that they must result in an optional type. Add constraint locator path for identifying constraints/variables that are part of the convert type passed into the system.
d70702c
to
775cca6
Compare
CI seemed stuck, so rebased/squashed. @swift-ci Please smoke test. |
@swift-ci please test source compatibility |
Looks like the only failure is |
So that they must result in an optional type. The pre-existing error remains for when the result type isn't optional, but with this added constraint, initializer expressions that were ambiguous before can now choose correct overloads.
Resolves SR-8347.