@@ -2315,7 +2315,8 @@ namespace {
2315
2315
cast<TypedPattern>(pattern)->getSubPattern (), locator,
2316
2316
Type (), bindPatternVarsOneWay);
2317
2317
CS.addConstraint (
2318
- ConstraintKind::Conversion, subPatternType, openedType, locator);
2318
+ ConstraintKind::Conversion, subPatternType, openedType,
2319
+ locator.withPathElement (LocatorPathElt::PatternMatch (pattern)));
2319
2320
return setType (openedType);
2320
2321
}
2321
2322
@@ -2352,7 +2353,7 @@ namespace {
2352
2353
2353
2354
Type eltTy = getTypeForPattern (
2354
2355
tupleElt.getPattern (),
2355
- locator. withPathElement ( LocatorPathElt::TupleElement (i)) ,
2356
+ locator,
2356
2357
externalEltType,
2357
2358
bindPatternVarsOneWay);
2358
2359
tupleTypeElts.push_back (TupleTypeElt (eltTy, tupleElt.getLabel ()));
@@ -2368,7 +2369,8 @@ namespace {
2368
2369
CS.getConstraintLocator (locator), TVO_CanBindToNoEscape);
2369
2370
CS.addConstraint (
2370
2371
ConstraintKind::OptionalObject, externalPatternType,
2371
- objVar, locator);
2372
+ objVar,
2373
+ locator.withPathElement (LocatorPathElt::PatternMatch (pattern)));
2372
2374
2373
2375
externalPatternType = objVar;
2374
2376
}
@@ -2386,7 +2388,9 @@ namespace {
2386
2388
2387
2389
Type castType =
2388
2390
resolveTypeReferenceInExpression (isPattern->getCastTypeLoc ());
2389
- castType = CS.openUnboundGenericType (castType, locator);
2391
+ castType = CS.openUnboundGenericType (
2392
+ castType,
2393
+ locator.withPathElement (LocatorPathElt::PatternMatch (pattern)));
2390
2394
2391
2395
Type subPatternType =
2392
2396
getTypeForPattern (isPattern->getSubPattern (), locator, castType,
@@ -2395,7 +2399,8 @@ namespace {
2395
2399
// Make sure we can cast from the subpattern type to the type we're
2396
2400
// checking; if it's impossible, fail.
2397
2401
CS.addConstraint (
2398
- ConstraintKind::CheckedCast, subPatternType, castType, locator);
2402
+ ConstraintKind::CheckedCast, subPatternType, castType,
2403
+ locator.withPathElement (LocatorPathElt::PatternMatch (pattern)));
2399
2404
2400
2405
return setType (subPatternType);
2401
2406
}
@@ -2422,7 +2427,9 @@ namespace {
2422
2427
// Resolve the parent type.
2423
2428
Type parentType =
2424
2429
resolveTypeReferenceInExpression (enumPattern->getParentType ());
2425
- parentType = CS.openUnboundGenericType (parentType, locator);
2430
+ parentType = CS.openUnboundGenericType (
2431
+ parentType,
2432
+ locator.withPathElement (LocatorPathElt::PatternMatch (pattern)));
2426
2433
2427
2434
// Perform member lookup into the parent's metatype.
2428
2435
Type parentMetaType = MetatypeType::get (parentType);
@@ -2433,8 +2440,9 @@ namespace {
2433
2440
2434
2441
// Parent type needs to be convertible to the pattern type; this
2435
2442
// accounts for cases where the pattern type is existential.
2436
- CS.addConstraint (ConstraintKind::Conversion, parentType, patternType,
2437
- locator);
2443
+ CS.addConstraint (
2444
+ ConstraintKind::Conversion, parentType, patternType,
2445
+ locator.withPathElement (LocatorPathElt::PatternMatch (pattern)));
2438
2446
2439
2447
baseType = parentType;
2440
2448
} else {
@@ -2470,8 +2478,9 @@ namespace {
2470
2478
ConstraintKind::Equal, functionType, memberType,
2471
2479
locator.withPathElement (LocatorPathElt::PatternMatch (pattern)));
2472
2480
2473
- CS.addConstraint (ConstraintKind::Conversion, outputType, baseType,
2474
- locator);
2481
+ CS.addConstraint (
2482
+ ConstraintKind::Conversion, outputType, baseType,
2483
+ locator.withPathElement (LocatorPathElt::PatternMatch (pattern)));
2475
2484
}
2476
2485
2477
2486
return setType (patternType);
@@ -4265,10 +4274,18 @@ bool ConstraintSystem::generateConstraints(
4265
4274
// For any pattern variable that has a parent variable (i.e., another
4266
4275
// pattern variable with the same name in the same case), require that
4267
4276
// the types be equivalent.
4268
- pattern->forEachVariable ([&](VarDecl *var) {
4277
+ pattern->forEachNode ([&](Pattern *pattern) {
4278
+ auto namedPattern = dyn_cast<NamedPattern>(pattern);
4279
+ if (!namedPattern)
4280
+ return ;
4281
+
4282
+ auto var = namedPattern->getDecl ();
4269
4283
if (auto parentVar = var->getParentVarDecl ()) {
4270
4284
addConstraint (
4271
- ConstraintKind::Equal, getType (parentVar), getType (var), locator);
4285
+ ConstraintKind::Equal, getType (parentVar), getType (var),
4286
+ getConstraintLocator (
4287
+ locator,
4288
+ LocatorPathElt::PatternMatch (namedPattern)));
4272
4289
}
4273
4290
});
4274
4291
}
0 commit comments