@@ -2438,17 +2438,12 @@ namespace {
2438
2438
// / \param locator The locator to use for generated constraints and
2439
2439
// / type variables.
2440
2440
// /
2441
- // / \param externalPatternType The type imposed by the enclosing pattern,
2442
- // / if any. This will be non-null in cases where there is, e.g., a
2443
- // / pattern such as "is SubClass".
2444
- // /
2445
2441
// / \param bindPatternVarsOneWay When true, generate fresh type variables
2446
2442
// / for the types of each variable declared within the pattern, along
2447
2443
// / with a one-way constraint binding that to the type to which the
2448
2444
// / variable will be ascribed or inferred.
2449
2445
Type getTypeForPattern (
2450
2446
Pattern *pattern, ConstraintLocatorBuilder locator,
2451
- Type externalPatternType,
2452
2447
bool bindPatternVarsOneWay,
2453
2448
PatternBindingDecl *patternBinding = nullptr ,
2454
2449
unsigned patternBindingIndex = 0 ) {
@@ -2476,19 +2471,11 @@ namespace {
2476
2471
case PatternKind::Paren: {
2477
2472
auto *paren = cast<ParenPattern>(pattern);
2478
2473
2479
- // Parentheses don't affect the canonical type, but record them as
2480
- // type sugar.
2481
- if (externalPatternType &&
2482
- isa<ParenType>(externalPatternType.getPointer ())) {
2483
- externalPatternType = cast<ParenType>(externalPatternType.getPointer ())
2484
- ->getUnderlyingType ();
2485
- }
2486
-
2487
2474
auto *subPattern = paren->getSubPattern ();
2488
2475
auto underlyingType = getTypeForPattern (
2489
2476
subPattern,
2490
2477
locator.withPathElement (LocatorPathElt::PatternMatch (subPattern)),
2491
- externalPatternType, bindPatternVarsOneWay);
2478
+ bindPatternVarsOneWay);
2492
2479
2493
2480
if (!underlyingType)
2494
2481
return Type ();
@@ -2497,7 +2484,7 @@ namespace {
2497
2484
}
2498
2485
case PatternKind::Binding: {
2499
2486
auto *subPattern = cast<BindingPattern>(pattern)->getSubPattern ();
2500
- auto type = getTypeForPattern (subPattern, locator, externalPatternType,
2487
+ auto type = getTypeForPattern (subPattern, locator,
2501
2488
bindPatternVarsOneWay);
2502
2489
2503
2490
if (!type)
@@ -2526,9 +2513,7 @@ namespace {
2526
2513
locator.withPathElement (LocatorPathElt::PatternMatch (pattern));
2527
2514
2528
2515
// Always prefer a contextual type when it's available.
2529
- if (externalPatternType) {
2530
- type = externalPatternType;
2531
- } else if (auto *initializer = getInitializerExpr ()) {
2516
+ if (auto *initializer = getInitializerExpr ()) {
2532
2517
// For initialization always assume a type of initializer.
2533
2518
type = CS.getType (initializer)->getRValueType ();
2534
2519
} else {
@@ -2608,18 +2593,13 @@ namespace {
2608
2593
// diagnostic in the middle of the solver path.
2609
2594
2610
2595
CS.addConstraint (ConstraintKind::OneWayEqual, oneWayVarType,
2611
- externalPatternType ? externalPatternType : varType,
2612
- locator);
2596
+ varType, locator);
2613
2597
}
2614
2598
2615
2599
// Ascribe a type to the declaration so it's always available to
2616
2600
// constraint system.
2617
2601
if (oneWayVarType) {
2618
2602
CS.setType (var, oneWayVarType);
2619
- } else if (externalPatternType) {
2620
- // If there is an externally imposed type, that's what the
2621
- // declaration is going to be bound to.
2622
- CS.setType (var, externalPatternType);
2623
2603
} else {
2624
2604
// Otherwise, let's use the type of the pattern. The type
2625
2605
// of the declaration has to be r-value, so let's add an
@@ -2708,7 +2688,7 @@ namespace {
2708
2688
Type subPatternType = getTypeForPattern (
2709
2689
subPattern,
2710
2690
locator.withPathElement (LocatorPathElt::PatternMatch (subPattern)),
2711
- openedType, bindPatternVarsOneWay);
2691
+ bindPatternVarsOneWay);
2712
2692
2713
2693
if (!subPatternType)
2714
2694
return Type ();
@@ -2731,38 +2711,16 @@ namespace {
2731
2711
case PatternKind::Tuple: {
2732
2712
auto tuplePat = cast<TuplePattern>(pattern);
2733
2713
2734
- // If there's an externally-imposed type, decompose it into element
2735
- // types so long as we have the right number of such types.
2736
- SmallVector<AnyFunctionType::Param, 4 > externalEltTypes;
2737
- if (externalPatternType) {
2738
- decomposeTuple (externalPatternType, externalEltTypes);
2739
-
2740
- // If we have the wrong number of elements, we may not be able to
2741
- // provide more specific types.
2742
- if (tuplePat->getNumElements () != externalEltTypes.size ()) {
2743
- externalEltTypes.clear ();
2744
-
2745
- // Implicit tupling.
2746
- if (tuplePat->getNumElements () == 1 ) {
2747
- externalEltTypes.push_back (
2748
- AnyFunctionType::Param (externalPatternType));
2749
- }
2750
- }
2751
- }
2752
-
2753
2714
SmallVector<TupleTypeElt, 4 > tupleTypeElts;
2754
2715
tupleTypeElts.reserve (tuplePat->getNumElements ());
2755
2716
for (unsigned i = 0 , e = tuplePat->getNumElements (); i != e; ++i) {
2756
2717
auto &tupleElt = tuplePat->getElement (i);
2757
- Type externalEltType;
2758
- if (!externalEltTypes.empty ())
2759
- externalEltType = externalEltTypes[i].getPlainType ();
2760
2718
2761
2719
auto *eltPattern = tupleElt.getPattern ();
2762
2720
Type eltTy = getTypeForPattern (
2763
2721
eltPattern,
2764
2722
locator.withPathElement (LocatorPathElt::PatternMatch (eltPattern)),
2765
- externalEltType, bindPatternVarsOneWay);
2723
+ bindPatternVarsOneWay);
2766
2724
2767
2725
if (!eltTy)
2768
2726
return Type ();
@@ -2774,25 +2732,12 @@ namespace {
2774
2732
}
2775
2733
2776
2734
case PatternKind::OptionalSome: {
2777
- // Remove an optional from the object type.
2778
- if (externalPatternType) {
2779
- Type objVar = CS.createTypeVariable (
2780
- CS.getConstraintLocator (
2781
- locator.withPathElement (ConstraintLocator::OptionalPayload)),
2782
- TVO_CanBindToNoEscape);
2783
- CS.addConstraint (
2784
- ConstraintKind::OptionalObject, externalPatternType, objVar,
2785
- locator.withPathElement (LocatorPathElt::PatternMatch (pattern)));
2786
-
2787
- externalPatternType = objVar;
2788
- }
2789
-
2790
2735
auto *subPattern = cast<OptionalSomePattern>(pattern)->getSubPattern ();
2791
2736
// The subpattern must have optional type.
2792
2737
Type subPatternType = getTypeForPattern (
2793
2738
subPattern,
2794
2739
locator.withPathElement (LocatorPathElt::PatternMatch (subPattern)),
2795
- externalPatternType, bindPatternVarsOneWay);
2740
+ bindPatternVarsOneWay);
2796
2741
2797
2742
if (!subPatternType)
2798
2743
return Type ();
@@ -2827,7 +2772,7 @@ namespace {
2827
2772
auto subPatternType = getTypeForPattern (
2828
2773
subPattern,
2829
2774
locator.withPathElement (LocatorPathElt::PatternMatch (subPattern)),
2830
- castType, bindPatternVarsOneWay);
2775
+ bindPatternVarsOneWay);
2831
2776
2832
2777
// NOTE: The order here is important! Pattern matching equality is
2833
2778
// not symmetric (we need to fix that either by using a different
@@ -2912,18 +2857,6 @@ namespace {
2912
2857
locator.withPathElement (LocatorPathElt::PatternMatch (pattern)));
2913
2858
2914
2859
baseType = parentType;
2915
- // Perform member lookup into the external pattern metatype. e.g.
2916
- // `case let .test(tuple) as Test`.
2917
- } else if (externalPatternType) {
2918
- Type externalMetaType = MetatypeType::get (externalPatternType);
2919
-
2920
- CS.addValueMemberConstraint (
2921
- externalMetaType, enumPattern->getName (), memberType, CurDC,
2922
- functionRefKind, {},
2923
- CS.getConstraintLocator (locator,
2924
- LocatorPathElt::PatternMatch (pattern)));
2925
-
2926
- baseType = externalPatternType;
2927
2860
} else {
2928
2861
// Use the pattern type for member lookup.
2929
2862
CS.addUnresolvedValueMemberConstraint (
@@ -2941,7 +2874,7 @@ namespace {
2941
2874
Type subPatternType = getTypeForPattern (
2942
2875
subPattern,
2943
2876
locator.withPathElement (LocatorPathElt::PatternMatch (subPattern)),
2944
- Type (), bindPatternVarsOneWay);
2877
+ bindPatternVarsOneWay);
2945
2878
2946
2879
if (!subPatternType)
2947
2880
return Type ();
@@ -4846,7 +4779,7 @@ Type ConstraintSystem::generateConstraints(
4846
4779
bool bindPatternVarsOneWay, PatternBindingDecl *patternBinding,
4847
4780
unsigned patternIndex) {
4848
4781
ConstraintGenerator cg (*this , nullptr );
4849
- return cg.getTypeForPattern (pattern, locator, Type (), bindPatternVarsOneWay,
4782
+ return cg.getTypeForPattern (pattern, locator, bindPatternVarsOneWay,
4850
4783
patternBinding, patternIndex);
4851
4784
}
4852
4785
0 commit comments