Skip to content

[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

Merged

Conversation

gregomni
Copy link
Contributor

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.

Type convertTo = convertType.getType();
if (options.contains(TypeCheckExprFlags::ExpressionTypeMustBeOptional)) {
assert(!convertTo && "convertType and type check options conflict");
Type var = cs.createTypeVariable(cs.getConstraintLocator(expr));
Copy link
Contributor

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.

@gregomni gregomni force-pushed the disambiguateOptionalPatternBinding branch from 6fb68bc to 9e5d9c3 Compare July 26, 2018 03:28
DynamicLookupResult,
/// \brief The desired convert type passed in to the constraint system.
ConvertType,
Copy link
Contributor

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?

@gregomni
Copy link
Contributor Author

@xedin Sure thing!

Copy link
Contributor

@xedin xedin left a comment

Choose a reason for hiding this comment

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

LGTM!

@gregomni
Copy link
Contributor Author

@swift-ci Please smoke test and merge.

@gregomni
Copy link
Contributor Author

Missed a spot where the new locator path info needs to be stripped back off for diagnosis.

@swift-ci Please smoke test and merge.

@gregomni
Copy link
Contributor Author

@swift-ci Please smoke test.

@xedin
Copy link
Contributor

xedin commented Jul 27, 2018

@swift-ci please test source compatibility

@gregomni gregomni force-pushed the disambiguateOptionalPatternBinding branch from 17f2725 to d70702c Compare July 28, 2018 01:05
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.
@gregomni gregomni force-pushed the disambiguateOptionalPatternBinding branch from d70702c to 775cca6 Compare July 28, 2018 01:05
@gregomni
Copy link
Contributor Author

CI seemed stuck, so rebased/squashed.

@swift-ci Please smoke test.

@xedin
Copy link
Contributor

xedin commented Jul 28, 2018

@swift-ci please test source compatibility

@xedin
Copy link
Contributor

xedin commented Jul 28, 2018

Looks like the only failure is SwiftNIO which is unrelated, so this should be good to go.

@gregomni gregomni merged commit a726dee into swiftlang:master Jul 28, 2018
@gregomni gregomni deleted the disambiguateOptionalPatternBinding branch August 18, 2020 23:13
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.

2 participants