Skip to content

Commit 80ac793

Browse files
committed
[CSGen] Adjust locators for some patterns
In each of the following situations `getTypeForPattern` would add a new pattern element to the path: - Element of a tuple pattern - Sub-pattern of a typed pattern - Sub-pattern of optional .some
1 parent feba039 commit 80ac793

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

lib/Sema/CSGen.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2342,15 +2342,17 @@ namespace {
23422342

23432343
Type openedType = CS.openUnboundGenericType(type, locator);
23442344

2345+
auto *subPattern = cast<TypedPattern>(pattern)->getSubPattern();
23452346
// Determine the subpattern type. It will be convertible to the
23462347
// ascribed type.
2347-
Type subPatternType =
2348-
getTypeForPattern(
2349-
cast<TypedPattern>(pattern)->getSubPattern(), locator,
2350-
Type(), bindPatternVarsOneWay);
2348+
Type subPatternType = getTypeForPattern(
2349+
subPattern,
2350+
locator.withPathElement(LocatorPathElt::PatternMatch(subPattern)),
2351+
Type(), bindPatternVarsOneWay);
2352+
23512353
CS.addConstraint(
23522354
ConstraintKind::Conversion, subPatternType, openedType,
2353-
locator.withPathElement(LocatorPathElt::PatternMatch(pattern)));
2355+
locator.withPathElement(LocatorPathElt::PatternMatch(pattern)));
23542356
return setType(openedType);
23552357
}
23562358

@@ -2385,11 +2387,11 @@ namespace {
23852387
if (!externalEltTypes.empty())
23862388
externalEltType = externalEltTypes[i].getPlainType();
23872389

2390+
auto *eltPattern = tupleElt.getPattern();
23882391
Type eltTy = getTypeForPattern(
2389-
tupleElt.getPattern(),
2390-
locator,
2391-
externalEltType,
2392-
bindPatternVarsOneWay);
2392+
eltPattern,
2393+
locator.withPathElement(LocatorPathElt::PatternMatch(eltPattern)),
2394+
externalEltType, bindPatternVarsOneWay);
23932395
tupleTypeElts.push_back(TupleTypeElt(eltTy, tupleElt.getLabel()));
23942396
}
23952397

@@ -2410,9 +2412,11 @@ namespace {
24102412
externalPatternType = objVar;
24112413
}
24122414

2415+
auto *subPattern = cast<OptionalSomePattern>(pattern)->getSubPattern();
24132416
// The subpattern must have optional type.
24142417
Type subPatternType = getTypeForPattern(
2415-
cast<OptionalSomePattern>(pattern)->getSubPattern(), locator,
2418+
subPattern,
2419+
locator.withPathElement(LocatorPathElt::PatternMatch(subPattern)),
24162420
externalPatternType, bindPatternVarsOneWay);
24172421

24182422
return setType(OptionalType::get(subPatternType));

0 commit comments

Comments
 (0)