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