@@ -1354,29 +1354,31 @@ namespace {
1354
1354
1355
1355
auto locator = CS.getConstraintLocator (E);
1356
1356
1357
- if (auto *param = dyn_cast<ParamDecl>(E->getDecl ())) {
1357
+ // If this is a 'var' or 'let' declaration with already
1358
+ // resolved type, let's favor it.
1359
+ if (auto *VD = dyn_cast<VarDecl>(E->getDecl ())) {
1360
+ Type type;
1361
+ if (VD->hasInterfaceType ()) {
1362
+ type = VD->getInterfaceType ();
1363
+ if (type->hasTypeParameter ())
1364
+ type = VD->getDeclContext ()->mapTypeIntoContext (type);
1365
+ CS.setFavoredType (E, type.getPointer ());
1366
+ }
1367
+
1358
1368
// This can only happen when failure diangostics is trying
1359
1369
// to type-check expressions inside of a single-statement
1360
1370
// closure which refer to anonymous parameters, in this case
1361
1371
// let's either use type as written or allocate a fresh type
1362
1372
// variable, just like we do for closure type.
1363
- if (!CS.hasType (param)) {
1364
- Type paramType;
1365
- if (param->hasInterfaceType ()) {
1366
- paramType = param->getInterfaceType ();
1367
- if (paramType->hasTypeParameter ())
1368
- paramType =
1369
- param->getDeclContext ()->mapTypeIntoContext (paramType);
1370
-
1371
- if (paramType->hasUnboundGenericType ())
1372
- paramType = CS.openUnboundGenericType (paramType, locator);
1373
-
1374
- CS.setFavoredType (E, paramType.getPointer ());
1375
- } else {
1376
- paramType = CS.createTypeVariable (locator, TVO_CanBindToLValue);
1373
+ if (auto *PD = dyn_cast<ParamDecl>(VD)) {
1374
+ if (!CS.hasType (PD)) {
1375
+ if (type && type->hasUnboundGenericType ())
1376
+ type = CS.openUnboundGenericType (type, locator);
1377
+
1378
+ CS.setType (
1379
+ PD, type ? type
1380
+ : CS.createTypeVariable (locator, TVO_CanBindToLValue));
1377
1381
}
1378
-
1379
- CS.setType (param, paramType);
1380
1382
}
1381
1383
}
1382
1384
0 commit comments