mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[CSSimplify] Adjust replaceTypeVariablesWithFreshPacks to propagate holes
If type variable that is being replaces allowed holes, the new one should not lose this property.
This commit is contained in:
committed by
Pavel Yaskevich
parent
38ee650719
commit
943ef19a1d
@@ -2412,13 +2412,16 @@ static PackType *replaceTypeVariablesWithFreshPacks(ConstraintSystem &cs,
|
|||||||
auto elementLoc = cs.getConstraintLocator(loc,
|
auto elementLoc = cs.getConstraintLocator(loc,
|
||||||
LocatorPathElt::PackElement(freshTypeVars.size()));
|
LocatorPathElt::PackElement(freshTypeVars.size()));
|
||||||
if (packExpansionElt != nullptr) {
|
if (packExpansionElt != nullptr) {
|
||||||
auto *freshTypeVar =
|
auto *freshTypeVar = cs.createTypeVariable(
|
||||||
cs.createTypeVariable(elementLoc, TVO_CanBindToPack);
|
elementLoc,
|
||||||
|
TVO_CanBindToPack |
|
||||||
|
(typeVar->getImpl().canBindToHole() ? TVO_CanBindToHole : 0));
|
||||||
freshTypeVars.push_back(PackExpansionType::get(
|
freshTypeVars.push_back(PackExpansionType::get(
|
||||||
freshTypeVar, packExpansionElt->getCountType()));
|
freshTypeVar, packExpansionElt->getCountType()));
|
||||||
} else {
|
} else {
|
||||||
freshTypeVars.push_back(
|
freshTypeVars.push_back(cs.createTypeVariable(
|
||||||
cs.createTypeVariable(elementLoc, /*options=*/0));
|
elementLoc,
|
||||||
|
typeVar->getImpl().canBindToHole() ? TVO_CanBindToHole : 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -210,7 +210,7 @@ func concreteReturnFunctionInvalid() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func patternInstantiationTupleTest1<each T>() -> (repeat Array<each T>) {}
|
func patternInstantiationTupleTest1<each T>() -> (repeat Array<each T>) {}
|
||||||
// expected-note@-1 2 {{in call to function 'patternInstantiationTupleTest1()'}}
|
// expected-note@-1 {{in call to function 'patternInstantiationTupleTest1()'}}
|
||||||
func patternInstantiationTupleTest2<each T, each U>() -> (repeat Dictionary<each T, each U>) {}
|
func patternInstantiationTupleTest2<each T, each U>() -> (repeat Dictionary<each T, each U>) {}
|
||||||
|
|
||||||
func patternInstantiationFunctionTest1<each T>() -> (repeat Array<each T>) -> () {}
|
func patternInstantiationFunctionTest1<each T>() -> (repeat Array<each T>) -> () {}
|
||||||
@@ -240,10 +240,9 @@ func patternInstantiationConcreteValid() {
|
|||||||
|
|
||||||
func patternInstantiationConcreteInvalid() {
|
func patternInstantiationConcreteInvalid() {
|
||||||
let _: Set<Int> = patternInstantiationTupleTest1()
|
let _: Set<Int> = patternInstantiationTupleTest1()
|
||||||
// expected-error@-1 {{generic parameter 'each T' could not be inferred}}
|
// expected-error@-1 {{cannot convert value of type '(repeat Array<Pack{_}>)' to specified type 'Set<Int>'}}
|
||||||
// expected-error@-2 {{cannot convert value of type '(repeat Array<each T>)' to specified type 'Set<Int>'}}
|
|
||||||
|
|
||||||
let _: (Array<Int>, Set<String>) = patternInstantiationTupleTest1() // expected-error {{type of expression is ambiguous without more context}}
|
let _: (Array<Int>, Set<String>) = patternInstantiationTupleTest1() // expected-error {{'(repeat Array<Pack{Int, _}>)' is not convertible to '(Array<Int>, Set<String>)', tuples have a different number of elements}}
|
||||||
}
|
}
|
||||||
|
|
||||||
func patternInstantiationGenericValid<each T, each U>(t: repeat each T, u: repeat each U)
|
func patternInstantiationGenericValid<each T, each U>(t: repeat each T, u: repeat each U)
|
||||||
@@ -273,7 +272,7 @@ func patternInstantiationGenericInvalid<each T: Hashable>(t: repeat each T) {
|
|||||||
let _: (repeat Set<each T>) = patternInstantiationTupleTest1() // expected-error {{cannot convert value of type '(repeat Array<each T>)' to specified type '(repeat Set<each T>)}}
|
let _: (repeat Set<each T>) = patternInstantiationTupleTest1() // expected-error {{cannot convert value of type '(repeat Array<each T>)' to specified type '(repeat Set<each T>)}}
|
||||||
// expected-error@-1 {{generic parameter 'each T' could not be inferred}}
|
// expected-error@-1 {{generic parameter 'each T' could not be inferred}}
|
||||||
|
|
||||||
let _: (repeat Array<each T>, Set<String>) = patternInstantiationTupleTest1() // expected-error {{type of expression is ambiguous without more context}}
|
let _: (repeat Array<each T>, Set<String>) = patternInstantiationTupleTest1() // expected-error {{'(repeat Array<Pack{repeat each T, _}>)' is not convertible to '(repeat Array<each T>, Set<String>)', tuples have a different number of elements}}
|
||||||
}
|
}
|
||||||
|
|
||||||
// rdar://107996926 - Vanishing metatype of tuple not supported
|
// rdar://107996926 - Vanishing metatype of tuple not supported
|
||||||
|
|||||||
Reference in New Issue
Block a user