@@ -2255,6 +2255,8 @@ namespace {
2255
2255
2256
2256
switch (pattern->getKind ()) {
2257
2257
case PatternKind::Paren: {
2258
+ auto *paren = cast<ParenPattern>(pattern);
2259
+
2258
2260
// Parentheses don't affect the canonical type, but record them as
2259
2261
// type sugar.
2260
2262
if (externalPatternType &&
@@ -2263,13 +2265,14 @@ namespace {
2263
2265
->getUnderlyingType ();
2264
2266
}
2265
2267
2266
- return setType (
2267
- ParenType::get (
2268
- CS.getASTContext (),
2269
- getTypeForPattern (
2270
- cast<ParenPattern>(pattern)->getSubPattern (), locator,
2271
- externalPatternType,
2272
- bindPatternVarsOneWay)));
2268
+ auto underlyingType =
2269
+ getTypeForPattern (paren->getSubPattern (), locator,
2270
+ externalPatternType, bindPatternVarsOneWay);
2271
+
2272
+ if (!underlyingType)
2273
+ return Type ();
2274
+
2275
+ return setType (ParenType::get (CS.getASTContext (), underlyingType));
2273
2276
}
2274
2277
case PatternKind::Var:
2275
2278
// Var doesn't affect the type.
@@ -2374,10 +2377,14 @@ namespace {
2374
2377
2375
2378
Type type = TypeChecker::typeCheckPattern (contextualPattern);
2376
2379
2380
+ if (!type)
2381
+ return Type ();
2382
+
2377
2383
// Look through reference storage types.
2378
2384
type = type->getReferenceStorageReferent ();
2379
2385
2380
2386
Type openedType = CS.openUnboundGenericType (type, locator);
2387
+ assert (openedType);
2381
2388
2382
2389
auto *subPattern = cast<TypedPattern>(pattern)->getSubPattern ();
2383
2390
// Determine the subpattern type. It will be convertible to the
@@ -2387,6 +2394,9 @@ namespace {
2387
2394
locator.withPathElement (LocatorPathElt::PatternMatch (subPattern)),
2388
2395
openedType, bindPatternVarsOneWay);
2389
2396
2397
+ if (!subPatternType)
2398
+ return Type ();
2399
+
2390
2400
CS.addConstraint (
2391
2401
ConstraintKind::Conversion, subPatternType, openedType,
2392
2402
locator.withPathElement (LocatorPathElt::PatternMatch (pattern)));
@@ -2429,6 +2439,10 @@ namespace {
2429
2439
eltPattern,
2430
2440
locator.withPathElement (LocatorPathElt::PatternMatch (eltPattern)),
2431
2441
externalEltType, bindPatternVarsOneWay);
2442
+
2443
+ if (!eltTy)
2444
+ return Type ();
2445
+
2432
2446
tupleTypeElts.push_back (TupleTypeElt (eltTy, tupleElt.getLabel ()));
2433
2447
}
2434
2448
@@ -2456,6 +2470,9 @@ namespace {
2456
2470
locator.withPathElement (LocatorPathElt::PatternMatch (subPattern)),
2457
2471
externalPatternType, bindPatternVarsOneWay);
2458
2472
2473
+ if (!subPatternType)
2474
+ return Type ();
2475
+
2459
2476
return setType (OptionalType::get (subPatternType));
2460
2477
}
2461
2478
@@ -2464,16 +2481,25 @@ namespace {
2464
2481
2465
2482
Type castType =
2466
2483
resolveTypeReferenceInExpression (isPattern->getCastTypeLoc ());
2484
+
2485
+ if (!castType)
2486
+ return Type ();
2487
+
2467
2488
castType = CS.openUnboundGenericType (
2468
2489
castType,
2469
2490
locator.withPathElement (LocatorPathElt::PatternMatch (pattern)));
2470
2491
2492
+ assert (castType);
2493
+
2471
2494
auto *subPattern = isPattern->getSubPattern ();
2472
2495
Type subPatternType = getTypeForPattern (
2473
2496
subPattern,
2474
2497
locator.withPathElement (LocatorPathElt::PatternMatch (subPattern)),
2475
2498
castType, bindPatternVarsOneWay);
2476
2499
2500
+ if (!subPatternType)
2501
+ return Type ();
2502
+
2477
2503
// Make sure we can cast from the subpattern type to the type we're
2478
2504
// checking; if it's impossible, fail.
2479
2505
CS.addConstraint (
@@ -2506,11 +2532,16 @@ namespace {
2506
2532
Type parentType =
2507
2533
resolveTypeReferenceInExpression (enumPattern->getParentType ());
2508
2534
2535
+ if (!parentType)
2536
+ return Type ();
2537
+
2509
2538
parentType = CS.openUnboundGenericType (
2510
2539
parentType, CS.getConstraintLocator (
2511
2540
locator, {LocatorPathElt::PatternMatch (pattern),
2512
2541
ConstraintLocator::ParentType}));
2513
2542
2543
+ assert (parentType);
2544
+
2514
2545
// Perform member lookup into the parent's metatype.
2515
2546
Type parentMetaType = MetatypeType::get (parentType);
2516
2547
CS.addValueMemberConstraint (
@@ -2543,6 +2574,10 @@ namespace {
2543
2574
// types.
2544
2575
Type subPatternType = getTypeForPattern (
2545
2576
subPattern, locator, Type (), bindPatternVarsOneWay);
2577
+
2578
+ if (!subPatternType)
2579
+ return Type ();
2580
+
2546
2581
SmallVector<AnyFunctionType::Param, 4 > params;
2547
2582
AnyFunctionType::decomposeInput (subPatternType, params);
2548
2583
0 commit comments