@@ -817,8 +817,7 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE,
817817 : D->getInterfaceType ());
818818 } else {
819819 if (makeTypeValue) {
820- return TypeValueExpr::createForDecl (UDRE->getNameLoc (),
821- cast<GenericTypeParamDecl>(D));
820+ return TypeValueExpr::createForDecl (UDRE->getNameLoc (), D, LookupDC);
822821 } else {
823822 return TypeExpr::createForDecl (UDRE->getNameLoc (), D, LookupDC);
824823 }
@@ -1096,10 +1095,10 @@ class PreCheckTarget final : public ASTWalker {
10961095 // / Simplify expressions which are type sugar productions that got parsed
10971096 // / as expressions due to the parser not knowing which identifiers are
10981097 // / type names.
1099- Expr *simplifyTypeExpr (Expr *E);
1098+ TypeExpr *simplifyTypeExpr (Expr *E);
11001099
11011100 // / Simplify unresolved dot expressions which are nested type productions.
1102- Expr *simplifyNestedTypeExpr (UnresolvedDotExpr *UDE);
1101+ TypeExpr *simplifyNestedTypeExpr (UnresolvedDotExpr *UDE);
11031102
11041103 TypeExpr *simplifyUnresolvedSpecializeExpr (UnresolvedSpecializeExpr *USE);
11051104
@@ -1726,7 +1725,7 @@ void PreCheckTarget::diagnoseOutOfPlaceSingleValueStmtExprs(
17261725 }
17271726}
17281727
1729- Expr *PreCheckTarget::simplifyNestedTypeExpr (UnresolvedDotExpr *UDE) {
1728+ TypeExpr *PreCheckTarget::simplifyNestedTypeExpr (UnresolvedDotExpr *UDE) {
17301729 if (!UDE->getName ().isSimpleName () ||
17311730 UDE->getName ().isSpecial ())
17321731 return nullptr ;
@@ -1841,19 +1840,8 @@ Expr *PreCheckTarget::simplifyNestedTypeExpr(UnresolvedDotExpr *UDE) {
18411840 // If there is no nested type with this name, we have a lookup of
18421841 // a non-type member, so leave the expression as-is.
18431842 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 );
18571845 }
18581846 }
18591847
@@ -2132,7 +2120,7 @@ static bool isTildeOperator(Expr *expr) {
21322120// / Simplify expressions which are type sugar productions that got parsed
21332121// / as expressions due to the parser not knowing which identifiers are
21342122// / type names.
2135- Expr *PreCheckTarget::simplifyTypeExpr (Expr *E) {
2123+ TypeExpr *PreCheckTarget::simplifyTypeExpr (Expr *E) {
21362124 // If it's already a type expression, return it.
21372125 if (auto typeExpr = dyn_cast<TypeExpr>(E))
21382126 return typeExpr;
@@ -2331,7 +2319,7 @@ Expr *PreCheckTarget::simplifyTypeExpr(Expr *E) {
23312319
23322320 // When simplifying a type expr like "(P1 & P2) -> (P3 & P4) -> Int",
23332321 // 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)) {
23352323 auto ArgRepr = ArgsTypeExpr->getTypeRepr ();
23362324 if (auto *TTyRepr = dyn_cast<TupleTypeRepr>(ArgRepr))
23372325 return TTyRepr;
@@ -2352,7 +2340,7 @@ Expr *PreCheckTarget::simplifyTypeExpr(Expr *E) {
23522340
23532341 // When simplifying a type expr like "P1 & P2 -> P3 & P4 -> Int",
23542342 // 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))
23562344 return ArgsTypeExpr->getTypeRepr ();
23572345 return nullptr ;
23582346 };
@@ -2391,8 +2379,7 @@ Expr *PreCheckTarget::simplifyTypeExpr(Expr *E) {
23912379 // Fold '~P' into a composition type.
23922380 if (auto *unaryExpr = dyn_cast<PrefixUnaryExpr>(E)) {
23932381 if (isTildeOperator (unaryExpr->getFn ())) {
2394- if (auto operand = dyn_cast_or_null<TypeExpr>(
2395- simplifyTypeExpr (unaryExpr->getOperand ()))) {
2382+ if (auto operand = simplifyTypeExpr (unaryExpr->getOperand ())) {
23962383 auto inverseTypeRepr = new (Ctx) InverseTypeRepr (
23972384 unaryExpr->getLoc (), operand->getTypeRepr ());
23982385 return new (Ctx) TypeExpr (inverseTypeRepr);
@@ -2412,7 +2399,7 @@ Expr *PreCheckTarget::simplifyTypeExpr(Expr *E) {
24122399 // If the lhs is another binary expression, we have a multi element
24132400 // composition: 'A & B & C' is parsed as ((A & B) & C); we get
24142401 // the protocols from the lhs here
2415- if (auto expr = dyn_cast_or_null<TypeExpr>( simplifyTypeExpr (lhsExpr) ))
2402+ if (auto expr = simplifyTypeExpr (lhsExpr))
24162403 if (auto *repr = dyn_cast<CompositionTypeRepr>(expr->getTypeRepr ()))
24172404 // add the protocols to our list
24182405 for (auto proto : repr->getTypes ())
0 commit comments