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