@@ -1558,8 +1558,10 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
1558
1558
break ;
1559
1559
1560
1560
case TypeKind::Tuple: {
1561
+ assert (!type2->is <LValueType>() && " Unexpected lvalue type!" );
1561
1562
// Try the tuple-to-tuple conversion.
1562
- conversionsOrFixes.push_back (ConversionRestrictionKind::TupleToTuple);
1563
+ if (!type1->is <LValueType>())
1564
+ conversionsOrFixes.push_back (ConversionRestrictionKind::TupleToTuple);
1563
1565
break ;
1564
1566
}
1565
1567
@@ -1568,7 +1570,9 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
1568
1570
case TypeKind::Class: {
1569
1571
auto nominal1 = cast<NominalType>(desugar1);
1570
1572
auto nominal2 = cast<NominalType>(desugar2);
1571
- if (nominal1->getDecl () == nominal2->getDecl ()) {
1573
+ assert (!type2->is <LValueType>() && " Unexpected lvalue type!" );
1574
+ if (!type1->is <LValueType>() &&
1575
+ nominal1->getDecl () == nominal2->getDecl ()) {
1572
1576
conversionsOrFixes.push_back (ConversionRestrictionKind::DeepEquality);
1573
1577
}
1574
1578
@@ -1579,15 +1583,19 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
1579
1583
auto class2 = cast<ClassDecl>(nominal2->getDecl ());
1580
1584
1581
1585
// CF -> Objective-C via toll-free bridging.
1582
- if (class1->getForeignClassKind () == ClassDecl::ForeignKind::CFType &&
1586
+ assert (!type2->is <LValueType>() && " Unexpected lvalue type!" );
1587
+ if (!type1->is <LValueType>() &&
1588
+ class1->getForeignClassKind () == ClassDecl::ForeignKind::CFType &&
1583
1589
class2->getForeignClassKind () != ClassDecl::ForeignKind::CFType &&
1584
1590
class1->getAttrs ().hasAttribute <ObjCBridgedAttr>()) {
1585
1591
conversionsOrFixes.push_back (
1586
1592
ConversionRestrictionKind::CFTollFreeBridgeToObjC);
1587
1593
}
1588
1594
1589
1595
// Objective-C -> CF via toll-free bridging.
1590
- if (class2->getForeignClassKind () == ClassDecl::ForeignKind::CFType &&
1596
+ assert (!type2->is <LValueType>() && " Unexpected lvalue type!" );
1597
+ if (!type1->is <LValueType>() &&
1598
+ class2->getForeignClassKind () == ClassDecl::ForeignKind::CFType &&
1591
1599
class1->getForeignClassKind () != ClassDecl::ForeignKind::CFType &&
1592
1600
class2->getAttrs ().hasAttribute <ObjCBridgedAttr>()) {
1593
1601
conversionsOrFixes.push_back (
@@ -1678,7 +1686,8 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
1678
1686
auto bound1 = cast<BoundGenericType>(desugar1);
1679
1687
auto bound2 = cast<BoundGenericType>(desugar2);
1680
1688
1681
- if (bound1->getDecl () == bound2->getDecl ()) {
1689
+ assert (!type2->is <LValueType>() && " Unexpected lvalue type!" );
1690
+ if (!type1->is <LValueType>() && bound1->getDecl () == bound2->getDecl ()) {
1682
1691
conversionsOrFixes.push_back (ConversionRestrictionKind::DeepEquality);
1683
1692
}
1684
1693
break ;
@@ -1713,12 +1722,13 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
1713
1722
// there is at most one non-defaulted element.
1714
1723
// For non-argument tuples, we can do the same conversion but not
1715
1724
// to a tuple with varargs.
1716
- if ((tuple2->getNumElements () == 1 &&
1717
- !tuple2->getElement (0 ).isVararg ()) ||
1718
- (kind >= ConstraintKind::Conversion &&
1719
- tuple2->getElementForScalarInit () >= 0 &&
1720
- (isArgumentTupleConversion ||
1721
- !tuple2->getVarArgsBaseType ()))) {
1725
+ if (!type1->is <LValueType>() &&
1726
+ ((tuple2->getNumElements () == 1 &&
1727
+ !tuple2->getElement (0 ).isVararg ()) ||
1728
+ (kind >= ConstraintKind::Conversion &&
1729
+ tuple2->getElementForScalarInit () >= 0 &&
1730
+ (isArgumentTupleConversion ||
1731
+ !tuple2->getVarArgsBaseType ())))) {
1722
1732
conversionsOrFixes.push_back (
1723
1733
ConversionRestrictionKind::ScalarToTuple);
1724
1734
@@ -1732,6 +1742,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
1732
1742
type2->getClassOrBoundGenericClass () &&
1733
1743
type1->getClassOrBoundGenericClass ()
1734
1744
!= type2->getClassOrBoundGenericClass ()) {
1745
+ assert (!type2->is <LValueType>() && " Unexpected lvalue type!" );
1735
1746
conversionsOrFixes.push_back (ConversionRestrictionKind::Superclass);
1736
1747
}
1737
1748
@@ -1740,7 +1751,9 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
1740
1751
// Don't allow this in operator contexts or we'll end up allowing
1741
1752
// 'T() == U()' for unrelated T and U that just happen to be Hashable.
1742
1753
// We can remove this special case when we implement operator hiding.
1743
- if (kind != ConstraintKind::OperatorArgumentConversion) {
1754
+ if (!type1->is <LValueType>() &&
1755
+ kind != ConstraintKind::OperatorArgumentConversion) {
1756
+ assert (!type2->is <LValueType>() && " Unexpected lvalue type!" );
1744
1757
conversionsOrFixes.push_back (
1745
1758
ConversionRestrictionKind::HashableToAnyHashable);
1746
1759
}
@@ -1800,16 +1813,20 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
1800
1813
}
1801
1814
1802
1815
// Special implicit nominal conversions.
1803
- if (kind >= ConstraintKind::Conversion) {
1816
+ if (!type1->is <LValueType>() &&
1817
+ kind >= ConstraintKind::Conversion) {
1804
1818
// Array -> Array.
1805
1819
if (isArrayType (desugar1) && isArrayType (desugar2)) {
1820
+ assert (!type2->is <LValueType>() && " Unexpected lvalue type!" );
1806
1821
conversionsOrFixes.push_back (ConversionRestrictionKind::ArrayUpcast);
1807
1822
// Dictionary -> Dictionary.
1808
1823
} else if (isDictionaryType (desugar1) && isDictionaryType (desugar2)) {
1824
+ assert (!type2->is <LValueType>() && " Unexpected lvalue type!" );
1809
1825
conversionsOrFixes.push_back (
1810
1826
ConversionRestrictionKind::DictionaryUpcast);
1811
1827
// Set -> Set.
1812
1828
} else if (isSetType (desugar1) && isSetType (desugar2)) {
1829
+ assert (!type2->is <LValueType>() && " Unexpected lvalue type!" );
1813
1830
conversionsOrFixes.push_back (
1814
1831
ConversionRestrictionKind::SetUpcast);
1815
1832
}
@@ -1981,7 +1998,13 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
1981
1998
// we hit commit_to_conversions below, but we have to add a token restriction
1982
1999
// to ensure we wrap the metatype value in a metatype erasure.
1983
2000
if (concrete && type2->isExistentialType () &&
2001
+ !type1->is <LValueType>() &&
1984
2002
kind >= ConstraintKind::Subtype) {
2003
+
2004
+ // Penalize conversions to Any.
2005
+ if (kind >= ConstraintKind::Conversion && type2->isAny ())
2006
+ increaseScore (ScoreKind::SK_EmptyExistentialConversion);
2007
+
1985
2008
conversionsOrFixes.push_back (ConversionRestrictionKind::Existential);
1986
2009
}
1987
2010
@@ -1992,7 +2015,8 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
1992
2015
{
1993
2016
BoundGenericType *boundGenericType2;
1994
2017
1995
- if (concrete && kind >= ConstraintKind::Subtype &&
2018
+ if (concrete && !type1->is <LValueType>() &&
2019
+ kind >= ConstraintKind::Subtype &&
1996
2020
(boundGenericType2 = type2->getAs <BoundGenericType>())) {
1997
2021
auto decl2 = boundGenericType2->getDecl ();
1998
2022
if (auto optionalKind2 = decl2->classifyAsOptionalType ()) {
@@ -2025,6 +2049,7 @@ ConstraintSystem::matchTypes(Type type1, Type type2, ConstraintKind kind,
2025
2049
ConversionRestrictionKind::ValueToOptional);
2026
2050
}
2027
2051
}
2052
+
2028
2053
}
2029
2054
2030
2055
// A value of type T! can be (unsafely) forced to U if T
0 commit comments