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