@@ -1096,10 +1096,10 @@ class PreCheckTarget final : public ASTWalker {
1096
1096
// / Simplify expressions which are type sugar productions that got parsed
1097
1097
// / as expressions due to the parser not knowing which identifiers are
1098
1098
// / type names.
1099
- TypeExpr *simplifyTypeExpr (Expr *E);
1099
+ Expr *simplifyTypeExpr (Expr *E);
1100
1100
1101
1101
// / Simplify unresolved dot expressions which are nested type productions.
1102
- TypeExpr *simplifyNestedTypeExpr (UnresolvedDotExpr *UDE);
1102
+ Expr *simplifyNestedTypeExpr (UnresolvedDotExpr *UDE);
1103
1103
1104
1104
TypeExpr *simplifyUnresolvedSpecializeExpr (UnresolvedSpecializeExpr *USE);
1105
1105
@@ -1726,7 +1726,7 @@ void PreCheckTarget::diagnoseOutOfPlaceSingleValueStmtExprs(
1726
1726
}
1727
1727
}
1728
1728
1729
- TypeExpr *PreCheckTarget::simplifyNestedTypeExpr (UnresolvedDotExpr *UDE) {
1729
+ Expr *PreCheckTarget::simplifyNestedTypeExpr (UnresolvedDotExpr *UDE) {
1730
1730
if (!UDE->getName ().isSimpleName () ||
1731
1731
UDE->getName ().isSpecial ())
1732
1732
return nullptr ;
@@ -1841,8 +1841,19 @@ TypeExpr *PreCheckTarget::simplifyNestedTypeExpr(UnresolvedDotExpr *UDE) {
1841
1841
// If there is no nested type with this name, we have a lookup of
1842
1842
// a non-type member, so leave the expression as-is.
1843
1843
if (Result.size () == 1 ) {
1844
- return TypeExpr::createForMemberDecl (InnerTypeRepr, UDE->getNameLoc (),
1845
- Result.front ().Member );
1844
+ auto resultDecl = Result.front ().Member ;
1845
+
1846
+ if (isa<GenericTypeParamDecl>(resultDecl) &&
1847
+ cast<GenericTypeParamDecl>(resultDecl)->isValue ()) {
1848
+ auto gtpd = cast<GenericTypeParamDecl>(resultDecl);
1849
+ return TypeValueExpr::createForMemberDecl (InnerTypeRepr,
1850
+ UDE->getNameLoc (),
1851
+ gtpd);
1852
+
1853
+ } else {
1854
+ return TypeExpr::createForMemberDecl (InnerTypeRepr, UDE->getNameLoc (),
1855
+ resultDecl);
1856
+ }
1846
1857
}
1847
1858
}
1848
1859
@@ -2121,7 +2132,7 @@ static bool isTildeOperator(Expr *expr) {
2121
2132
// / Simplify expressions which are type sugar productions that got parsed
2122
2133
// / as expressions due to the parser not knowing which identifiers are
2123
2134
// / type names.
2124
- TypeExpr *PreCheckTarget::simplifyTypeExpr (Expr *E) {
2135
+ Expr *PreCheckTarget::simplifyTypeExpr (Expr *E) {
2125
2136
// If it's already a type expression, return it.
2126
2137
if (auto typeExpr = dyn_cast<TypeExpr>(E))
2127
2138
return typeExpr;
@@ -2320,7 +2331,7 @@ TypeExpr *PreCheckTarget::simplifyTypeExpr(Expr *E) {
2320
2331
2321
2332
// When simplifying a type expr like "(P1 & P2) -> (P3 & P4) -> Int",
2322
2333
// it may have been folded at the same time; recursively simplify it.
2323
- if (auto ArgsTypeExpr = simplifyTypeExpr (E)) {
2334
+ if (auto ArgsTypeExpr = dyn_cast<TypeExpr>( simplifyTypeExpr (E) )) {
2324
2335
auto ArgRepr = ArgsTypeExpr->getTypeRepr ();
2325
2336
if (auto *TTyRepr = dyn_cast<TupleTypeRepr>(ArgRepr))
2326
2337
return TTyRepr;
@@ -2341,7 +2352,7 @@ TypeExpr *PreCheckTarget::simplifyTypeExpr(Expr *E) {
2341
2352
2342
2353
// When simplifying a type expr like "P1 & P2 -> P3 & P4 -> Int",
2343
2354
// it may have been folded at the same time; recursively simplify it.
2344
- if (auto ArgsTypeExpr = simplifyTypeExpr (E))
2355
+ if (auto ArgsTypeExpr = dyn_cast<TypeExpr>( simplifyTypeExpr (E) ))
2345
2356
return ArgsTypeExpr->getTypeRepr ();
2346
2357
return nullptr ;
2347
2358
};
@@ -2380,7 +2391,8 @@ TypeExpr *PreCheckTarget::simplifyTypeExpr(Expr *E) {
2380
2391
// Fold '~P' into a composition type.
2381
2392
if (auto *unaryExpr = dyn_cast<PrefixUnaryExpr>(E)) {
2382
2393
if (isTildeOperator (unaryExpr->getFn ())) {
2383
- if (auto operand = simplifyTypeExpr (unaryExpr->getOperand ())) {
2394
+ if (auto operand = dyn_cast<TypeExpr>(
2395
+ simplifyTypeExpr (unaryExpr->getOperand ()))) {
2384
2396
auto inverseTypeRepr = new (Ctx) InverseTypeRepr (
2385
2397
unaryExpr->getLoc (), operand->getTypeRepr ());
2386
2398
return new (Ctx) TypeExpr (inverseTypeRepr);
@@ -2400,7 +2412,7 @@ TypeExpr *PreCheckTarget::simplifyTypeExpr(Expr *E) {
2400
2412
// If the lhs is another binary expression, we have a multi element
2401
2413
// composition: 'A & B & C' is parsed as ((A & B) & C); we get
2402
2414
// the protocols from the lhs here
2403
- if (auto expr = simplifyTypeExpr (lhsExpr))
2415
+ if (auto expr = dyn_cast<TypeExpr>( simplifyTypeExpr (lhsExpr) ))
2404
2416
if (auto *repr = dyn_cast<CompositionTypeRepr>(expr->getTypeRepr ()))
2405
2417
// add the protocols to our list
2406
2418
for (auto proto : repr->getTypes ())
0 commit comments