@@ -1354,33 +1354,20 @@ namespace {
13541354 Type visitDeclRefExpr (DeclRefExpr *E) {
13551355 auto locator = CS.getConstraintLocator (E);
13561356
1357- auto invalidateReference = [&]() -> Type {
1358- auto *hole = CS.createTypeVariable (locator, TVO_CanBindToHole);
1359- (void )CS.recordFix (AllowRefToInvalidDecl::create (CS, locator));
1360- CS.setType (E, hole);
1361- return hole;
1362- };
1363-
13641357 Type knownType;
13651358 if (auto *VD = dyn_cast<VarDecl>(E->getDecl ())) {
13661359 knownType = CS.getTypeIfAvailable (VD);
13671360 if (!knownType)
13681361 knownType = CS.getVarType (VD);
13691362
13701363 if (knownType) {
1371- // An out-of-scope type variable could be a type of a declaration
1372- // only in diagnostic mode when invalid variable declaration is
1373- // recursively referenced inside of a multi-statement closure
1374- // located somewhere within its initializer e.g.:
1375- // `let x = [<call>] { ... print(x) }`
1376- if (auto *typeVar = knownType->getAs <TypeVariableType>()) {
1377- if (!CS.isActiveTypeVariable (typeVar))
1378- return invalidateReference ();
1379- }
1380-
13811364 // If the known type has an error, bail out.
13821365 if (knownType->hasError ()) {
1383- return invalidateReference ();
1366+ auto *hole = CS.createTypeVariable (locator, TVO_CanBindToHole);
1367+ (void )CS.recordFix (AllowRefToInvalidDecl::create (CS, locator));
1368+ if (!CS.hasType (E))
1369+ CS.setType (E, hole);
1370+ return hole;
13841371 }
13851372
13861373 if (!knownType->hasPlaceholder ()) {
@@ -1397,7 +1384,10 @@ namespace {
13971384 // (in getTypeOfReference) so we can match non-error param types.
13981385 if (!knownType && E->getDecl ()->isInvalid () &&
13991386 !CS.isForCodeCompletion ()) {
1400- return invalidateReference ();
1387+ auto *hole = CS.createTypeVariable (locator, TVO_CanBindToHole);
1388+ (void )CS.recordFix (AllowRefToInvalidDecl::create (CS, locator));
1389+ CS.setType (E, hole);
1390+ return hole;
14011391 }
14021392
14031393 // Create an overload choice referencing this declaration and immediately
0 commit comments