@@ -1667,9 +1667,6 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
1667
1667
auto desugar1 = type1->getDesugaredType ();
1668
1668
auto desugar2 = type2->getDesugaredType ();
1669
1669
1670
- auto *typeVar1 = desugar1->getAs <TypeVariableType>();
1671
- auto *typeVar2 = desugar2->getAs <TypeVariableType>();
1672
-
1673
1670
// If the types are obviously equivalent, we're done.
1674
1671
if (desugar1->isEqual (desugar2))
1675
1672
return getTypeMatchSuccess ();
@@ -1699,6 +1696,9 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
1699
1696
return getTypeMatchAmbiguous ();
1700
1697
};
1701
1698
1699
+ auto *typeVar1 = dyn_cast<TypeVariableType>(desugar1);
1700
+ auto *typeVar2 = dyn_cast<TypeVariableType>(desugar2);
1701
+
1702
1702
// If either (or both) types are type variables, unify the type variables.
1703
1703
if (typeVar1 || typeVar2) {
1704
1704
// Handle the easy case of both being type variables, and being
@@ -1800,11 +1800,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
1800
1800
case ConstraintKind::Conversion:
1801
1801
case ConstraintKind::ArgumentConversion:
1802
1802
case ConstraintKind::OperatorArgumentConversion:
1803
- // We couldn't solve this constraint. If only one of the types is a type
1804
- // variable, perhaps we can do something with it below.
1805
- if (typeVar1 && typeVar2)
1806
- return formUnsolvedResult ();
1807
- break ;
1803
+ return formUnsolvedResult ();
1808
1804
1809
1805
case ConstraintKind::ApplicableFunction:
1810
1806
case ConstraintKind::DynamicCallableApplicableFunction:
@@ -1830,11 +1826,14 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
1830
1826
}
1831
1827
}
1832
1828
1833
- bool isTypeVarOrMember1 = desugar1->isTypeVariableOrMember ();
1834
- bool isTypeVarOrMember2 = desugar2->isTypeVariableOrMember ();
1829
+ // If one of the types is a member type of a type variable type,
1830
+ // there's nothing we can do.
1831
+ if (desugar1->isTypeVariableOrMember () ||
1832
+ desugar2->isTypeVariableOrMember ()) {
1833
+ return formUnsolvedResult ();
1834
+ }
1835
1835
1836
1836
llvm::SmallVector<RestrictionOrFix, 4 > conversionsOrFixes;
1837
- bool concrete = !isTypeVarOrMember1 && !isTypeVarOrMember2;
1838
1837
1839
1838
// Decompose parallel structure.
1840
1839
TypeMatchOptions subflags =
@@ -1854,29 +1853,28 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
1854
1853
#define BUILTIN_TYPE (id, parent ) case TypeKind::id:
1855
1854
#define TYPE (id, parent )
1856
1855
#include " swift/AST/TypeNodes.def"
1857
- case TypeKind::Module:
1858
- if (desugar1 == desugar2) {
1859
- return getTypeMatchSuccess ();
1860
- }
1861
- return getTypeMatchFailure (locator);
1862
1856
1863
1857
case TypeKind::Error:
1864
1858
case TypeKind::Unresolved:
1865
- return getTypeMatchFailure (locator);
1859
+ return getTypeMatchFailure (locator);
1866
1860
1867
1861
case TypeKind::GenericTypeParam:
1868
1862
llvm_unreachable (" unmapped dependent type in type checker" );
1869
1863
1864
+ case TypeKind::TypeVariable:
1865
+ llvm_unreachable (" type variables should have already been handled by now" );
1866
+
1870
1867
case TypeKind::DependentMember:
1871
1868
// Nothing we can solve.
1872
1869
return formUnsolvedResult ();
1873
1870
1874
- case TypeKind::TypeVariable :
1871
+ case TypeKind::Module :
1875
1872
case TypeKind::PrimaryArchetype:
1876
1873
case TypeKind::OpenedArchetype:
1877
1874
case TypeKind::NestedArchetype:
1878
- // Nothing to do here; handle type variables and archetypes below.
1879
- break ;
1875
+ // If two module types or archetypes were not already equal, there's
1876
+ // nothing more we can do.
1877
+ return getTypeMatchFailure (locator);
1880
1878
1881
1879
case TypeKind::Tuple: {
1882
1880
assert (!type2->is <LValueType>() && " Unexpected lvalue type!" );
@@ -2010,7 +2008,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
2010
2008
}
2011
2009
}
2012
2010
2013
- if (concrete && kind >= ConstraintKind::Subtype) {
2011
+ if (kind >= ConstraintKind::Subtype) {
2014
2012
// Subclass-to-superclass conversion.
2015
2013
if (type1->mayHaveSuperclass () &&
2016
2014
type2->getClassOrBoundGenericClass () &&
@@ -2166,7 +2164,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
2166
2164
return getTypeMatchSuccess ();
2167
2165
}
2168
2166
2169
- if (concrete && kind >= ConstraintKind::Conversion) {
2167
+ if (kind >= ConstraintKind::Conversion) {
2170
2168
// An lvalue of type T1 can be converted to a value of type T2 so long as
2171
2169
// T1 is convertible to T2 (by loading the value). Note that we cannot get
2172
2170
// a value of inout type as an lvalue though.
@@ -2301,7 +2299,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
2301
2299
}
2302
2300
}
2303
2301
2304
- if (concrete && kind >= ConstraintKind::OperatorArgumentConversion) {
2302
+ if (kind >= ConstraintKind::OperatorArgumentConversion) {
2305
2303
// If the RHS is an inout type, the LHS must be an @lvalue type.
2306
2304
if (auto *lvt = type1->getAs <LValueType>()) {
2307
2305
if (auto *iot = type2->getAs <InOutType>()) {
@@ -2317,7 +2315,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
2317
2315
// to U by force-unwrapping the source value.
2318
2316
// A value of type T, T?, or T! can be converted to type U? or U! if
2319
2317
// T is convertible to U.
2320
- if (concrete && !type1->is <LValueType>() && kind >= ConstraintKind::Subtype) {
2318
+ if (!type1->is <LValueType>() && kind >= ConstraintKind::Subtype) {
2321
2319
enumerateOptionalConversionRestrictions (
2322
2320
type1, type2, kind, locator,
2323
2321
[&](ConversionRestrictionKind restriction) {
@@ -2329,15 +2327,15 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
2329
2327
// literals.
2330
2328
if (auto elt = locator.last ()) {
2331
2329
if (elt->getKind () == ConstraintLocator::ClosureResult) {
2332
- if (concrete && kind >= ConstraintKind::Subtype &&
2330
+ if (kind >= ConstraintKind::Subtype &&
2333
2331
(type1->isUninhabited () || type2->isVoid ())) {
2334
2332
increaseScore (SK_FunctionConversion);
2335
2333
return getTypeMatchSuccess ();
2336
2334
}
2337
2335
}
2338
2336
}
2339
2337
2340
- if (concrete && kind == ConstraintKind::BindParam) {
2338
+ if (kind == ConstraintKind::BindParam) {
2341
2339
if (auto *iot = dyn_cast<InOutType>(desugar1)) {
2342
2340
if (auto *lvt = dyn_cast<LValueType>(desugar2)) {
2343
2341
return matchTypes (iot->getObjectType (), lvt->getObjectType (),
@@ -2351,7 +2349,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
2351
2349
// Attempt fixes iff it's allowed, both types are concrete and
2352
2350
// we are not in the middle of attempting one already.
2353
2351
bool attemptFixes =
2354
- shouldAttemptFixes () && concrete && !flags.contains (TMF_ApplyingFix);
2352
+ shouldAttemptFixes () && !flags.contains (TMF_ApplyingFix);
2355
2353
2356
2354
// When we hit this point, we're committed to the set of potential
2357
2355
// conversions recorded thus far.
@@ -2446,14 +2444,8 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
2446
2444
if (attemptFixes)
2447
2445
repairFailures (*this , type1, type2, conversionsOrFixes, locator);
2448
2446
2449
- if (conversionsOrFixes.empty ()) {
2450
- // If one of the types is a type variable or member thereof, we leave this
2451
- // unsolved.
2452
- if (isTypeVarOrMember1 || isTypeVarOrMember2)
2453
- return formUnsolvedResult ();
2454
-
2447
+ if (conversionsOrFixes.empty ())
2455
2448
return getTypeMatchFailure (locator);
2456
- }
2457
2449
2458
2450
// Where there is more than one potential conversion, create a disjunction
2459
2451
// so that we'll explore all of the options.
0 commit comments