@@ -1843,12 +1843,12 @@ Expr *PreCheckTarget::simplifyNestedTypeExpr(UnresolvedDotExpr *UDE) {
1843
1843
if (Result.size () == 1 ) {
1844
1844
auto resultDecl = Result.front ().Member ;
1845
1845
1846
- if (isa<GenericTypeParamDecl>(resultDecl) &&
1846
+ if (resultDecl &&
1847
+ isa<GenericTypeParamDecl>(resultDecl) &&
1847
1848
cast<GenericTypeParamDecl>(resultDecl)->isValue ()) {
1848
1849
auto gtpd = cast<GenericTypeParamDecl>(resultDecl);
1849
1850
return TypeValueExpr::createForMemberDecl (InnerTypeRepr,
1850
- UDE->getNameLoc (),
1851
- gtpd);
1851
+ UDE->getNameLoc (), gtpd);
1852
1852
1853
1853
} else {
1854
1854
return TypeExpr::createForMemberDecl (InnerTypeRepr, UDE->getNameLoc (),
@@ -1864,7 +1864,7 @@ TypeExpr *PreCheckTarget::simplifyUnresolvedSpecializeExpr(
1864
1864
UnresolvedSpecializeExpr *us) {
1865
1865
// If this is a reference type a specialized type, form a TypeExpr.
1866
1866
// The base should be a TypeExpr that we already resolved.
1867
- if (auto *te = dyn_cast <TypeExpr>(us->getSubExpr ())) {
1867
+ if (auto *te = dyn_cast_or_null <TypeExpr>(us->getSubExpr ())) {
1868
1868
if (auto *declRefTR =
1869
1869
dyn_cast_or_null<DeclRefTypeRepr>(te->getTypeRepr ())) {
1870
1870
return TypeExpr::createForSpecializedDecl (
@@ -2331,7 +2331,7 @@ Expr *PreCheckTarget::simplifyTypeExpr(Expr *E) {
2331
2331
2332
2332
// When simplifying a type expr like "(P1 & P2) -> (P3 & P4) -> Int",
2333
2333
// it may have been folded at the same time; recursively simplify it.
2334
- if (auto ArgsTypeExpr = dyn_cast <TypeExpr>(simplifyTypeExpr (E))) {
2334
+ if (auto ArgsTypeExpr = dyn_cast_or_null <TypeExpr>(simplifyTypeExpr (E))) {
2335
2335
auto ArgRepr = ArgsTypeExpr->getTypeRepr ();
2336
2336
if (auto *TTyRepr = dyn_cast<TupleTypeRepr>(ArgRepr))
2337
2337
return TTyRepr;
@@ -2352,7 +2352,7 @@ Expr *PreCheckTarget::simplifyTypeExpr(Expr *E) {
2352
2352
2353
2353
// When simplifying a type expr like "P1 & P2 -> P3 & P4 -> Int",
2354
2354
// it may have been folded at the same time; recursively simplify it.
2355
- if (auto ArgsTypeExpr = dyn_cast <TypeExpr>(simplifyTypeExpr (E)))
2355
+ if (auto ArgsTypeExpr = dyn_cast_or_null <TypeExpr>(simplifyTypeExpr (E)))
2356
2356
return ArgsTypeExpr->getTypeRepr ();
2357
2357
return nullptr ;
2358
2358
};
@@ -2391,7 +2391,7 @@ Expr *PreCheckTarget::simplifyTypeExpr(Expr *E) {
2391
2391
// Fold '~P' into a composition type.
2392
2392
if (auto *unaryExpr = dyn_cast<PrefixUnaryExpr>(E)) {
2393
2393
if (isTildeOperator (unaryExpr->getFn ())) {
2394
- if (auto operand = dyn_cast <TypeExpr>(
2394
+ if (auto operand = dyn_cast_or_null <TypeExpr>(
2395
2395
simplifyTypeExpr (unaryExpr->getOperand ()))) {
2396
2396
auto inverseTypeRepr = new (Ctx) InverseTypeRepr (
2397
2397
unaryExpr->getLoc (), operand->getTypeRepr ());
@@ -2412,7 +2412,7 @@ Expr *PreCheckTarget::simplifyTypeExpr(Expr *E) {
2412
2412
// If the lhs is another binary expression, we have a multi element
2413
2413
// composition: 'A & B & C' is parsed as ((A & B) & C); we get
2414
2414
// the protocols from the lhs here
2415
- if (auto expr = dyn_cast <TypeExpr>(simplifyTypeExpr (lhsExpr)))
2415
+ if (auto expr = dyn_cast_or_null <TypeExpr>(simplifyTypeExpr (lhsExpr)))
2416
2416
if (auto *repr = dyn_cast<CompositionTypeRepr>(expr->getTypeRepr ()))
2417
2417
// add the protocols to our list
2418
2418
for (auto proto : repr->getTypes ())
0 commit comments