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