@@ -2378,17 +2378,12 @@ namespace {
2378
2378
// / \param locator The locator to use for generated constraints and
2379
2379
// / type variables.
2380
2380
// /
2381
- // / \param externalPatternType The type imposed by the enclosing pattern,
2382
- // / if any. This will be non-null in cases where there is, e.g., a
2383
- // / pattern such as "is SubClass".
2384
- // /
2385
2381
// / \param bindPatternVarsOneWay When true, generate fresh type variables
2386
2382
// / for the types of each variable declared within the pattern, along
2387
2383
// / with a one-way constraint binding that to the type to which the
2388
2384
// / variable will be ascribed or inferred.
2389
2385
Type getTypeForPattern (
2390
2386
Pattern *pattern, ConstraintLocatorBuilder locator,
2391
- Type externalPatternType,
2392
2387
bool bindPatternVarsOneWay,
2393
2388
PatternBindingDecl *patternBinding = nullptr ,
2394
2389
unsigned patternBindingIndex = 0 ) {
@@ -2416,19 +2411,11 @@ namespace {
2416
2411
case PatternKind::Paren: {
2417
2412
auto *paren = cast<ParenPattern>(pattern);
2418
2413
2419
- // Parentheses don't affect the canonical type, but record them as
2420
- // type sugar.
2421
- if (externalPatternType &&
2422
- isa<ParenType>(externalPatternType.getPointer ())) {
2423
- externalPatternType = cast<ParenType>(externalPatternType.getPointer ())
2424
- ->getUnderlyingType ();
2425
- }
2426
-
2427
2414
auto *subPattern = paren->getSubPattern ();
2428
2415
auto underlyingType = getTypeForPattern (
2429
2416
subPattern,
2430
2417
locator.withPathElement (LocatorPathElt::PatternMatch (subPattern)),
2431
- externalPatternType, bindPatternVarsOneWay);
2418
+ bindPatternVarsOneWay);
2432
2419
2433
2420
if (!underlyingType)
2434
2421
return Type ();
@@ -2437,7 +2424,7 @@ namespace {
2437
2424
}
2438
2425
case PatternKind::Binding: {
2439
2426
auto *subPattern = cast<BindingPattern>(pattern)->getSubPattern ();
2440
- auto type = getTypeForPattern (subPattern, locator, externalPatternType,
2427
+ auto type = getTypeForPattern (subPattern, locator,
2441
2428
bindPatternVarsOneWay);
2442
2429
2443
2430
if (!type)
@@ -2463,9 +2450,7 @@ namespace {
2463
2450
};
2464
2451
2465
2452
// Always prefer a contextual type when it's available.
2466
- if (externalPatternType) {
2467
- type = externalPatternType;
2468
- } else if (auto *initializer = getInitializerExpr ()) {
2453
+ if (auto *initializer = getInitializerExpr ()) {
2469
2454
// For initialization always assume a type of initializer.
2470
2455
type = CS.getType (initializer)->getRValueType ();
2471
2456
} else {
@@ -2542,18 +2527,13 @@ namespace {
2542
2527
// diagnostic in the middle of the solver path.
2543
2528
2544
2529
CS.addConstraint (ConstraintKind::OneWayEqual, oneWayVarType,
2545
- externalPatternType ? externalPatternType : varType,
2546
- locator);
2530
+ varType, locator);
2547
2531
}
2548
2532
2549
2533
// Ascribe a type to the declaration so it's always available to
2550
2534
// constraint system.
2551
2535
if (oneWayVarType) {
2552
2536
CS.setType (var, oneWayVarType);
2553
- } else if (externalPatternType) {
2554
- // If there is an externally imposed type, that's what the
2555
- // declaration is going to be bound to.
2556
- CS.setType (var, externalPatternType);
2557
2537
} else {
2558
2538
// Otherwise, let's use the type of the pattern. The type
2559
2539
// of the declaration has to be r-value, so let's add an
@@ -2642,7 +2622,7 @@ namespace {
2642
2622
Type subPatternType = getTypeForPattern (
2643
2623
subPattern,
2644
2624
locator.withPathElement (LocatorPathElt::PatternMatch (subPattern)),
2645
- openedType, bindPatternVarsOneWay);
2625
+ bindPatternVarsOneWay);
2646
2626
2647
2627
if (!subPatternType)
2648
2628
return Type ();
@@ -2665,38 +2645,16 @@ namespace {
2665
2645
case PatternKind::Tuple: {
2666
2646
auto tuplePat = cast<TuplePattern>(pattern);
2667
2647
2668
- // If there's an externally-imposed type, decompose it into element
2669
- // types so long as we have the right number of such types.
2670
- SmallVector<AnyFunctionType::Param, 4 > externalEltTypes;
2671
- if (externalPatternType) {
2672
- decomposeTuple (externalPatternType, externalEltTypes);
2673
-
2674
- // If we have the wrong number of elements, we may not be able to
2675
- // provide more specific types.
2676
- if (tuplePat->getNumElements () != externalEltTypes.size ()) {
2677
- externalEltTypes.clear ();
2678
-
2679
- // Implicit tupling.
2680
- if (tuplePat->getNumElements () == 1 ) {
2681
- externalEltTypes.push_back (
2682
- AnyFunctionType::Param (externalPatternType));
2683
- }
2684
- }
2685
- }
2686
-
2687
2648
SmallVector<TupleTypeElt, 4 > tupleTypeElts;
2688
2649
tupleTypeElts.reserve (tuplePat->getNumElements ());
2689
2650
for (unsigned i = 0 , e = tuplePat->getNumElements (); i != e; ++i) {
2690
2651
auto &tupleElt = tuplePat->getElement (i);
2691
- Type externalEltType;
2692
- if (!externalEltTypes.empty ())
2693
- externalEltType = externalEltTypes[i].getPlainType ();
2694
2652
2695
2653
auto *eltPattern = tupleElt.getPattern ();
2696
2654
Type eltTy = getTypeForPattern (
2697
2655
eltPattern,
2698
2656
locator.withPathElement (LocatorPathElt::PatternMatch (eltPattern)),
2699
- externalEltType, bindPatternVarsOneWay);
2657
+ bindPatternVarsOneWay);
2700
2658
2701
2659
if (!eltTy)
2702
2660
return Type ();
@@ -2708,25 +2666,12 @@ namespace {
2708
2666
}
2709
2667
2710
2668
case PatternKind::OptionalSome: {
2711
- // Remove an optional from the object type.
2712
- if (externalPatternType) {
2713
- Type objVar = CS.createTypeVariable (
2714
- CS.getConstraintLocator (
2715
- locator.withPathElement (ConstraintLocator::OptionalPayload)),
2716
- TVO_CanBindToNoEscape);
2717
- CS.addConstraint (
2718
- ConstraintKind::OptionalObject, externalPatternType, objVar,
2719
- locator.withPathElement (LocatorPathElt::PatternMatch (pattern)));
2720
-
2721
- externalPatternType = objVar;
2722
- }
2723
-
2724
2669
auto *subPattern = cast<OptionalSomePattern>(pattern)->getSubPattern ();
2725
2670
// The subpattern must have optional type.
2726
2671
Type subPatternType = getTypeForPattern (
2727
2672
subPattern,
2728
2673
locator.withPathElement (LocatorPathElt::PatternMatch (subPattern)),
2729
- externalPatternType, bindPatternVarsOneWay);
2674
+ bindPatternVarsOneWay);
2730
2675
2731
2676
if (!subPatternType)
2732
2677
return Type ();
@@ -2760,7 +2705,7 @@ namespace {
2760
2705
auto subPatternType = getTypeForPattern (
2761
2706
subPattern,
2762
2707
locator.withPathElement (LocatorPathElt::PatternMatch (subPattern)),
2763
- castType, bindPatternVarsOneWay);
2708
+ bindPatternVarsOneWay);
2764
2709
2765
2710
// NOTE: The order here is important! Pattern matching equality is
2766
2711
// not symmetric (we need to fix that either by using a different
@@ -2845,18 +2790,6 @@ namespace {
2845
2790
locator.withPathElement (LocatorPathElt::PatternMatch (pattern)));
2846
2791
2847
2792
baseType = parentType;
2848
- // Perform member lookup into the external pattern metatype. e.g.
2849
- // `case let .test(tuple) as Test`.
2850
- } else if (externalPatternType) {
2851
- Type externalMetaType = MetatypeType::get (externalPatternType);
2852
-
2853
- CS.addValueMemberConstraint (
2854
- externalMetaType, enumPattern->getName (), memberType, CurDC,
2855
- functionRefKind, {},
2856
- CS.getConstraintLocator (locator,
2857
- LocatorPathElt::PatternMatch (pattern)));
2858
-
2859
- baseType = externalPatternType;
2860
2793
} else {
2861
2794
// Use the pattern type for member lookup.
2862
2795
CS.addUnresolvedValueMemberConstraint (
@@ -2874,7 +2807,7 @@ namespace {
2874
2807
Type subPatternType = getTypeForPattern (
2875
2808
subPattern,
2876
2809
locator.withPathElement (LocatorPathElt::PatternMatch (subPattern)),
2877
- Type (), bindPatternVarsOneWay);
2810
+ bindPatternVarsOneWay);
2878
2811
2879
2812
if (!subPatternType)
2880
2813
return Type ();
@@ -4723,7 +4656,7 @@ Type ConstraintSystem::generateConstraints(
4723
4656
bool bindPatternVarsOneWay, PatternBindingDecl *patternBinding,
4724
4657
unsigned patternIndex) {
4725
4658
ConstraintGenerator cg (*this , nullptr );
4726
- return cg.getTypeForPattern (pattern, locator, Type (), bindPatternVarsOneWay,
4659
+ return cg.getTypeForPattern (pattern, locator, bindPatternVarsOneWay,
4727
4660
patternBinding, patternIndex);
4728
4661
}
4729
4662
0 commit comments