Skip to content

Commit d1f79b1

Browse files
authored
Merge pull request #31571 from xedin/opt-any-inside-typed-pattern
[CSGen] Allow typed pattern to propagate its type to sub-pattern
2 parents 38dcbcf + 4c259ac commit d1f79b1

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)