@@ -939,6 +939,10 @@ namespace {
939
939
// / The expressions that are direct arguments of call expressions.
940
940
llvm::SmallPtrSet<Expr *, 4 > CallArgs;
941
941
942
+ // / Simplify TypeExprs which represent a fully-qualified module name only
943
+ // / into a DeclRefExpr.
944
+ DeclRefExpr *simplifyQualifiedModuleRef (Expr *TE);
945
+
942
946
// / Simplify expressions which are type sugar productions that got parsed
943
947
// / as expressions due to the parser not knowing which identifiers are
944
948
// / type names.
@@ -1329,6 +1333,11 @@ namespace {
1329
1333
return DAE;
1330
1334
}
1331
1335
1336
+ // Turn qualified references to modules into DeclRefExprs.
1337
+ if (auto DRE = simplifyQualifiedModuleRef (expr)) {
1338
+ return DRE;
1339
+ }
1340
+
1332
1341
// If this is a sugared type that needs to be folded into a single
1333
1342
// TypeExpr, do it.
1334
1343
if (auto *simplified = simplifyTypeExpr (expr))
@@ -1397,6 +1406,36 @@ bool PreCheckExpression::walkToClosureExprPre(ClosureExpr *closure) {
1397
1406
return true ;
1398
1407
}
1399
1408
1409
+ static TypeRepr *skipParens (TypeRepr *TR) {
1410
+ assert (TR);
1411
+ while (isa<TupleTypeRepr>(TR) && cast<TupleTypeRepr>(TR)->isParenType ())
1412
+ TR = cast<TupleTypeRepr>(TR)->getElement (0 ).Type ;
1413
+ return TR;
1414
+ }
1415
+
1416
+ DeclRefExpr *PreCheckExpression::simplifyQualifiedModuleRef (Expr *E) {
1417
+ auto TE = dyn_cast<TypeExpr>(E);
1418
+ if (!TE || !TE->getTypeRepr ()) return nullptr ;
1419
+
1420
+ TypeRepr * Repr = skipParens (TE->getTypeRepr ());
1421
+
1422
+ auto ATR = dyn_cast<AttributedTypeRepr>(Repr);
1423
+ if (!ATR || !ATR->getAttrs ().has (TAK_qualified)) return nullptr ;
1424
+
1425
+ Repr = skipParens (ATR->getTypeRepr ());
1426
+
1427
+ auto SITR = dyn_cast<SimpleIdentTypeRepr>(Repr);
1428
+ if (!SITR) return nullptr ;
1429
+
1430
+ auto modules = TC.lookupUnqualified (DC, SITR->getIdentifier (), SITR->getLoc (),
1431
+ NameLookupFlags::IncludeOnlyModules);
1432
+ if (modules.size () != 1 ) return nullptr ;
1433
+
1434
+ ConcreteDeclRef concreteRef (modules.front ().getValueDecl ());
1435
+ return new (TC.Context ) DeclRefExpr (concreteRef, DeclNameLoc (TE->getLoc ()),
1436
+ /* Implicit=*/ false );
1437
+ }
1438
+
1400
1439
TypeExpr *PreCheckExpression::simplifyNestedTypeExpr (UnresolvedDotExpr *UDE) {
1401
1440
if (!UDE->getName ().isSimpleName () ||
1402
1441
UDE->getName ().isSpecial ())
0 commit comments