@@ -1624,8 +1624,10 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
1624
1624
break ;
1625
1625
1626
1626
case TypeKind::Tuple: {
1627
+ assert (!type2->is <LValueType>() && " Unexpected lvalue type!" );
1627
1628
// Try the tuple-to-tuple conversion.
1628
- conversionsOrFixes.push_back (ConversionRestrictionKind::TupleToTuple);
1629
+ if (!type1->is <LValueType>())
1630
+ conversionsOrFixes.push_back (ConversionRestrictionKind::TupleToTuple);
1629
1631
break ;
1630
1632
}
1631
1633
@@ -1634,7 +1636,9 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
1634
1636
case TypeKind::Class: {
1635
1637
auto nominal1 = cast<NominalType>(desugar1);
1636
1638
auto nominal2 = cast<NominalType>(desugar2);
1637
- if (nominal1->getDecl () == nominal2->getDecl ()) {
1639
+ assert (!type2->is <LValueType>() && " Unexpected lvalue type!" );
1640
+ if (!type1->is <LValueType>() &&
1641
+ nominal1->getDecl () == nominal2->getDecl ()) {
1638
1642
conversionsOrFixes.push_back (ConversionRestrictionKind::DeepEquality);
1639
1643
}
1640
1644
@@ -1645,15 +1649,19 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
1645
1649
auto class2 = cast<ClassDecl>(nominal2->getDecl ());
1646
1650
1647
1651
// CF -> Objective-C via toll-free bridging.
1648
- if (class1->getForeignClassKind () == ClassDecl::ForeignKind::CFType &&
1652
+ assert (!type2->is <LValueType>() && " Unexpected lvalue type!" );
1653
+ if (!type1->is <LValueType>() &&
1654
+ class1->getForeignClassKind () == ClassDecl::ForeignKind::CFType &&
1649
1655
class2->getForeignClassKind () != ClassDecl::ForeignKind::CFType &&
1650
1656
class1->getAttrs ().hasAttribute <ObjCBridgedAttr>()) {
1651
1657
conversionsOrFixes.push_back (
1652
1658
ConversionRestrictionKind::CFTollFreeBridgeToObjC);
1653
1659
}
1654
1660
1655
1661
// Objective-C -> CF via toll-free bridging.
1656
- if (class2->getForeignClassKind () == ClassDecl::ForeignKind::CFType &&
1662
+ assert (!type2->is <LValueType>() && " Unexpected lvalue type!" );
1663
+ if (!type1->is <LValueType>() &&
1664
+ class2->getForeignClassKind () == ClassDecl::ForeignKind::CFType &&
1657
1665
class1->getForeignClassKind () != ClassDecl::ForeignKind::CFType &&
1658
1666
class2->getAttrs ().hasAttribute <ObjCBridgedAttr>()) {
1659
1667
conversionsOrFixes.push_back (
@@ -1744,7 +1752,8 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
1744
1752
auto bound1 = cast<BoundGenericType>(desugar1);
1745
1753
auto bound2 = cast<BoundGenericType>(desugar2);
1746
1754
1747
- if (bound1->getDecl () == bound2->getDecl ()) {
1755
+ assert (!type2->is <LValueType>() && " Unexpected lvalue type!" );
1756
+ if (!type1->is <LValueType>() && bound1->getDecl () == bound2->getDecl ()) {
1748
1757
conversionsOrFixes.push_back (ConversionRestrictionKind::DeepEquality);
1749
1758
}
1750
1759
break ;
@@ -1779,12 +1788,13 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
1779
1788
// there is at most one non-defaulted element.
1780
1789
// For non-argument tuples, we can do the same conversion but not
1781
1790
// to a tuple with varargs.
1782
- if ((tuple2->getNumElements () == 1 &&
1783
- !tuple2->getElement (0 ).isVararg ()) ||
1784
- (kind >= ConstraintKind::Conversion &&
1785
- tuple2->getElementForScalarInit () >= 0 &&
1786
- (isArgumentTupleConversion ||
1787
- !tuple2->getVarArgsBaseType ()))) {
1791
+ if (!type1->is <LValueType>() &&
1792
+ ((tuple2->getNumElements () == 1 &&
1793
+ !tuple2->getElement (0 ).isVararg ()) ||
1794
+ (kind >= ConstraintKind::Conversion &&
1795
+ tuple2->getElementForScalarInit () >= 0 &&
1796
+ (isArgumentTupleConversion ||
1797
+ !tuple2->getVarArgsBaseType ())))) {
1788
1798
conversionsOrFixes.push_back (
1789
1799
ConversionRestrictionKind::ScalarToTuple);
1790
1800
@@ -1798,6 +1808,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
1798
1808
type2->getClassOrBoundGenericClass () &&
1799
1809
type1->getClassOrBoundGenericClass ()
1800
1810
!= type2->getClassOrBoundGenericClass ()) {
1811
+ assert (!type2->is <LValueType>() && " Unexpected lvalue type!" );
1801
1812
conversionsOrFixes.push_back (ConversionRestrictionKind::Superclass);
1802
1813
}
1803
1814
@@ -1806,7 +1817,9 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
1806
1817
// Don't allow this in operator contexts or we'll end up allowing
1807
1818
// 'T() == U()' for unrelated T and U that just happen to be Hashable.
1808
1819
// We can remove this special case when we implement operator hiding.
1809
- if (kind != ConstraintKind::OperatorArgumentConversion) {
1820
+ if (!type1->is <LValueType>() &&
1821
+ kind != ConstraintKind::OperatorArgumentConversion) {
1822
+ assert (!type2->is <LValueType>() && " Unexpected lvalue type!" );
1810
1823
conversionsOrFixes.push_back (
1811
1824
ConversionRestrictionKind::HashableToAnyHashable);
1812
1825
}
@@ -1866,16 +1879,20 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
1866
1879
}
1867
1880
1868
1881
// Special implicit nominal conversions.
1869
- if (kind >= ConstraintKind::Conversion) {
1882
+ if (!type1->is <LValueType>() &&
1883
+ kind >= ConstraintKind::Conversion) {
1870
1884
// Array -> Array.
1871
1885
if (isArrayType (desugar1) && isArrayType (desugar2)) {
1886
+ assert (!type2->is <LValueType>() && " Unexpected lvalue type!" );
1872
1887
conversionsOrFixes.push_back (ConversionRestrictionKind::ArrayUpcast);
1873
1888
// Dictionary -> Dictionary.
1874
1889
} else if (isDictionaryType (desugar1) && isDictionaryType (desugar2)) {
1890
+ assert (!type2->is <LValueType>() && " Unexpected lvalue type!" );
1875
1891
conversionsOrFixes.push_back (
1876
1892
ConversionRestrictionKind::DictionaryUpcast);
1877
1893
// Set -> Set.
1878
1894
} else if (isSetType (desugar1) && isSetType (desugar2)) {
1895
+ assert (!type2->is <LValueType>() && " Unexpected lvalue type!" );
1879
1896
conversionsOrFixes.push_back (
1880
1897
ConversionRestrictionKind::SetUpcast);
1881
1898
}
@@ -2047,15 +2064,21 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
2047
2064
// we hit commit_to_conversions below, but we have to add a token restriction
2048
2065
// to ensure we wrap the metatype value in a metatype erasure.
2049
2066
if (concrete && type2->isExistentialType () &&
2067
+ !type1->is <LValueType>() &&
2050
2068
kind >= ConstraintKind::Subtype) {
2069
+
2070
+ // Penalize conversions to Any.
2071
+ if (kind >= ConstraintKind::Conversion && type2->isAny ())
2072
+ increaseScore (ScoreKind::SK_EmptyExistentialConversion);
2073
+
2051
2074
conversionsOrFixes.push_back (ConversionRestrictionKind::Existential);
2052
2075
}
2053
2076
2054
2077
// A value of type T! can be converted to type U if T is convertible
2055
2078
// to U by force-unwrapping the source value.
2056
2079
// A value of type T, T?, or T! can be converted to type U? or U! if
2057
2080
// T is convertible to U.
2058
- if (concrete && kind >= ConstraintKind::Subtype) {
2081
+ if (concrete && !type1-> is <LValueType>() && kind >= ConstraintKind::Subtype) {
2059
2082
enumerateOptionalConversionRestrictions (
2060
2083
type1, type2, kind, locator,
2061
2084
[&](ConversionRestrictionKind restriction) {
0 commit comments