Skip to content

Commit 4c259ac

Browse files
committed
[CSGen] Allow typed pattern to propagate its type to sub-pattern
Currently we always generate a new type variable for any pattern (represented as `_` in the source), but in cases where it's a sub-pattern of a typed pattern e.g. `let _: Foo = ...` it makes more sense to pass a type to it directly otherwise type variable allocated for any pattern gets disconnected from the rest of the constraint system.
1 parent 11b9586 commit 4c259ac

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

lib/Sema/CSGen.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2277,10 +2277,13 @@ namespace {
22772277
getTypeForPattern(
22782278
cast<VarPattern>(pattern)->getSubPattern(), locator,
22792279
externalPatternType, bindPatternVarsOneWay));
2280+
22802281
case PatternKind::Any: {
22812282
return setType(
2282-
CS.createTypeVariable(CS.getConstraintLocator(locator),
2283-
TVO_CanBindToNoEscape));
2283+
externalPatternType
2284+
? externalPatternType
2285+
: CS.createTypeVariable(CS.getConstraintLocator(locator),
2286+
TVO_CanBindToNoEscape));
22842287
}
22852288

22862289
case PatternKind::Named: {
@@ -2382,7 +2385,7 @@ namespace {
23822385
Type subPatternType = getTypeForPattern(
23832386
subPattern,
23842387
locator.withPathElement(LocatorPathElt::PatternMatch(subPattern)),
2385-
Type(), bindPatternVarsOneWay);
2388+
openedType, bindPatternVarsOneWay);
23862389

23872390
CS.addConstraint(
23882391
ConstraintKind::Conversion, subPatternType, openedType,

0 commit comments

Comments
 (0)