Skip to content

Commit ed9bb09

Browse files
committed
[CSSimplify] Adjust replaceTypeVariablesWithFreshPacks to propagate holes
If type variable that is being replaces allowed holes, the new one should not lose this property.
1 parent 511c3c3 commit ed9bb09

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2412,13 +2412,16 @@ static PackType *replaceTypeVariablesWithFreshPacks(ConstraintSystem &cs,
24122412
auto elementLoc = cs.getConstraintLocator(loc,
24132413
LocatorPathElt::PackElement(freshTypeVars.size()));
24142414
if (packExpansionElt != nullptr) {
2415-
auto *freshTypeVar =
2416-
cs.createTypeVariable(elementLoc, TVO_CanBindToPack);
2415+
auto *freshTypeVar = cs.createTypeVariable(
2416+
elementLoc,
2417+
TVO_CanBindToPack |
2418+
(typeVar->getImpl().canBindToHole() ? TVO_CanBindToHole : 0));
24172419
freshTypeVars.push_back(PackExpansionType::get(
24182420
freshTypeVar, packExpansionElt->getCountType()));
24192421
} else {
2420-
freshTypeVars.push_back(
2421-
cs.createTypeVariable(elementLoc, /*options=*/0));
2422+
freshTypeVars.push_back(cs.createTypeVariable(
2423+
elementLoc,
2424+
typeVar->getImpl().canBindToHole() ? TVO_CanBindToHole : 0));
24222425
}
24232426
}
24242427
}

test/Constraints/pack_expansion_types.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ func concreteReturnFunctionInvalid() {
210210
}
211211

212212
func patternInstantiationTupleTest1<each T>() -> (repeat Array<each T>) {}
213-
// expected-note@-1 2 {{in call to function 'patternInstantiationTupleTest1()'}}
213+
// expected-note@-1 {{in call to function 'patternInstantiationTupleTest1()'}}
214214
func patternInstantiationTupleTest2<each T, each U>() -> (repeat Dictionary<each T, each U>) {}
215215

216216
func patternInstantiationFunctionTest1<each T>() -> (repeat Array<each T>) -> () {}
@@ -240,10 +240,9 @@ func patternInstantiationConcreteValid() {
240240

241241
func patternInstantiationConcreteInvalid() {
242242
let _: Set<Int> = patternInstantiationTupleTest1()
243-
// expected-error@-1 {{generic parameter 'each T' could not be inferred}}
244-
// expected-error@-2 {{cannot convert value of type '(repeat Array<each T>)' to specified type 'Set<Int>'}}
243+
// expected-error@-1 {{cannot convert value of type '(repeat Array<Pack{_}>)' to specified type 'Set<Int>'}}
245244

246-
let _: (Array<Int>, Set<String>) = patternInstantiationTupleTest1() // expected-error {{type of expression is ambiguous without more context}}
245+
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}}
247246
}
248247

249248
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) {
273272
let _: (repeat Set<each T>) = patternInstantiationTupleTest1() // expected-error {{cannot convert value of type '(repeat Array<each T>)' to specified type '(repeat Set<each T>)}}
274273
// expected-error@-1 {{generic parameter 'each T' could not be inferred}}
275274

276-
let _: (repeat Array<each T>, Set<String>) = patternInstantiationTupleTest1() // expected-error {{type of expression is ambiguous without more context}}
275+
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}}
277276
}
278277

279278
// rdar://107996926 - Vanishing metatype of tuple not supported

0 commit comments

Comments
 (0)