@@ -1391,8 +1391,9 @@ TypeExpr *PreCheckExpression::simplifyNestedTypeExpr(UnresolvedDotExpr *UDE) {
1391
1391
1392
1392
// Qualified type lookup with a module base is represented as a DeclRefExpr
1393
1393
// and not a TypeExpr.
1394
- if (auto *DRE = dyn_cast<DeclRefExpr>(UDE->getBase ())) {
1395
- if (auto *TD = dyn_cast<TypeDecl>(DRE->getDecl ())) {
1394
+ auto handleNestedTypeLookup = [&](
1395
+ TypeDecl *TD, DeclNameLoc ParentNameLoc
1396
+ ) -> TypeExpr * {
1396
1397
// See if the type has a member type with this name.
1397
1398
auto Result = TypeChecker::lookupMemberType (
1398
1399
DC, TD->getDeclaredInterfaceType (), Name,
@@ -1402,10 +1403,43 @@ TypeExpr *PreCheckExpression::simplifyNestedTypeExpr(UnresolvedDotExpr *UDE) {
1402
1403
// a non-type member, so leave the expression as-is.
1403
1404
if (Result.size () == 1 ) {
1404
1405
return TypeExpr::createForMemberDecl (
1405
- DRE-> getNameLoc () , TD, UDE->getNameLoc (), Result.front ().Member );
1406
+ ParentNameLoc , TD, UDE->getNameLoc (), Result.front ().Member );
1406
1407
}
1408
+
1409
+ return nullptr ;
1410
+ };
1411
+
1412
+ if (auto *DRE = dyn_cast<DeclRefExpr>(UDE->getBase ())) {
1413
+ if (auto *TD = dyn_cast<TypeDecl>(DRE->getDecl ()))
1414
+ return handleNestedTypeLookup (TD, DRE->getNameLoc ());
1415
+
1416
+ return nullptr ;
1417
+ }
1418
+
1419
+ // Determine whether there is exactly one type declaration, where all
1420
+ // other declarations are macros.
1421
+ if (auto *ODRE = dyn_cast<OverloadedDeclRefExpr>(UDE->getBase ())) {
1422
+ TypeDecl *FoundTD = nullptr ;
1423
+ for (auto *D : ODRE->getDecls ()) {
1424
+ if (auto *TD = dyn_cast<TypeDecl>(D)) {
1425
+ if (FoundTD)
1426
+ return nullptr ;
1427
+
1428
+ FoundTD = TD;
1429
+ continue ;
1430
+ }
1431
+
1432
+ // Ignore macros; they can't have any nesting.
1433
+ if (isa<MacroDecl>(D))
1434
+ continue ;
1435
+
1436
+ // Anything else prevents folding.
1437
+ return nullptr ;
1407
1438
}
1408
1439
1440
+ if (FoundTD)
1441
+ return handleNestedTypeLookup (FoundTD, ODRE->getNameLoc ());
1442
+
1409
1443
return nullptr ;
1410
1444
}
1411
1445
0 commit comments