Skip to content

Commit bc97f6f

Browse files
committed
[Diagnostics] Don't fail simplifyFixConstraint for tuples of pack expansion types.
1 parent 8bdff20 commit bc97f6f

File tree

2 files changed

+78
-21
lines changed

2 files changed

+78
-21
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13712,11 +13712,15 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyFixConstraint(
1371213712
auto smaller = lhsLarger ? rhs : lhs;
1371313713
llvm::SmallVector<TupleTypeElt, 4> newTupleTypes;
1371413714

13715-
// FIXME: For now, if either side contains pack expansion types, just fail.
13715+
// FIXME: For now, if either side contains pack expansion types, consider
13716+
// the fix constraint solved without trying to figure out which tuple
13717+
// elements were part of the pack.
1371613718
{
1371713719
if (lhs->containsPackExpansionType() ||
1371813720
rhs->containsPackExpansionType()) {
13719-
return SolutionKind::Error;
13721+
if (recordFix(fix))
13722+
return SolutionKind::Error;
13723+
return SolutionKind::Solved;
1372013724
}
1372113725
}
1372213726

test/Constraints/pack_expansion_types.swift

Lines changed: 72 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,28 @@
33
// REQUIRES: asserts
44

55
func returnTuple1<T...>() -> (repeat each T) { fatalError() }
6+
// expected-note@-1 3 {{in call to function 'returnTuple1()'}}
67

78
func returnTuple2<T...>() -> (Int, repeat each T) { fatalError() }
9+
// expected-note@-1 3 {{in call to function 'returnTuple2()'}}
810

911
func returnTupleLabel1<T...>() -> (x: repeat each T) { fatalError() }
12+
// expected-note@-1 2 {{in call to function 'returnTupleLabel1()'}}
1013

1114
func returnTupleLabel2<T...>() -> (Int, x: repeat each T) { fatalError() }
15+
// expected-note@-1 2 {{in call to function 'returnTupleLabel2()'}}
1216

1317
func returnTupleLabel3<T...>() -> (Int, repeat each T, y: Float) { fatalError() }
18+
// expected-note@-1 3 {{in call to function 'returnTupleLabel3()'}}
1419

15-
func returnTupleLabel4<T...>() -> (Int, x: repeat each T, y: Float) { fatalError() } // expected-note {{in call to function 'returnTupleLabel4()'}}
20+
func returnTupleLabel4<T...>() -> (Int, x: repeat each T, y: Float) { fatalError() }
21+
// expected-note@-1 2 {{in call to function 'returnTupleLabel4()'}}
1622

1723
func returnTupleLabel5<T..., U...>() -> (Int, repeat each T, y: repeat each U) { fatalError() }
24+
// expected-note@-1 3 {{in call to function 'returnTupleLabel5()'}}
1825

19-
func returnTupleLabel6<T..., U...>() -> (Int, x: repeat each T, y: repeat each U) { fatalError() } // expected-note {{in call to function 'returnTupleLabel6()'}}
26+
func returnTupleLabel6<T..., U...>() -> (Int, x: repeat each T, y: repeat each U) { fatalError() }
27+
// expected-note@-1 {{in call to function 'returnTupleLabel6()'}}
2028

2129
func concreteReturnTupleValid() {
2230
let _: () = returnTuple1()
@@ -59,11 +67,26 @@ func concreteReturnTupleValid() {
5967
}
6068

6169
func concreteReturnTypeInvalid() {
62-
let _: (x: Int) = returnTuple1() // expected-error {{type of expression is ambiguous without more context}}
63-
let _: () = returnTuple2() // expected-error {{type of expression is ambiguous without more context}}
64-
let _: (x: Int) = returnTupleLabel3() // expected-error {{type of expression is ambiguous without more context}}
65-
let _: (Int, Int, y: Float) = returnTupleLabel4() // expected-error {{type of expression is ambiguous without more context}}
66-
let _: () = returnTupleLabel5() // expected-error {{type of expression is ambiguous without more context}}
70+
let _: (x: Int) = returnTuple1()
71+
// expected-error@-1 {{cannot convert value of type '(T...)' to specified type '(x: Int)'}}
72+
// expected-error@-2 {{generic parameter 'T' could not be inferred}}
73+
74+
let _: () = returnTuple2()
75+
// expected-error@-1 {{'(Int, T...)' is not convertible to '()', tuples have a different number of elements}}
76+
// expected-error@-2 {{generic parameter 'T' could not be inferred}}
77+
78+
let _: (x: Int) = returnTupleLabel3()
79+
// expected-error@-1 {{'(Int, T..., y: Float)' is not convertible to '(x: Int)', tuples have a different number of elements}}
80+
// expected-error@-2 {{generic parameter 'T' could not be inferred}}
81+
82+
let _: (Int, Int, y: Float) = returnTupleLabel4()
83+
// expected-error@-1 {{cannot convert value of type '(Int, x: T..., y: Float)' to specified type '(Int, Int, y: Float)'}}
84+
// expected-error@-2 {{generic parameter 'T' could not be inferred}}
85+
86+
let _: () = returnTupleLabel5()
87+
// expected-error@-1 {{'(Int, T..., y: U...)' is not convertible to '()', tuples have a different number of elements}}
88+
// expected-error@-2 {{generic parameter 'T' could not be inferred}}
89+
// expected-error@-3 {{generic parameter 'U' could not be inferred}}
6790
}
6891

6992
func genericReturnTupleValid<T...>(_: repeat each T) {
@@ -93,30 +116,60 @@ func genericReturnTupleValid<T...>(_: repeat each T) {
93116
}
94117

95118
func genericReturnTupleInvalid<T...>(_: repeat each T) {
96-
let _: (x: repeat each T) = returnTuple1() // expected-error {{type of expression is ambiguous without more context}}
97-
let _: (x: Int, repeat each T) = returnTuple1() // expected-error {{type of expression is ambiguous without more context}}
119+
let _: (x: repeat each T) = returnTuple1()
120+
// expected-error@-1 {{cannot convert value of type '(T...)' to specified type '(x: T...)'}}
121+
// expected-error@-2 {{generic parameter 'T' could not be inferred}}
98122

99-
let _: (Int, x: repeat each T) = returnTuple2() // expected-error {{type of expression is ambiguous without more context}}
100-
let _: (Int, x: String, repeat each T) = returnTuple2() // expected-error {{type of expression is ambiguous without more context}}
123+
let _: (x: Int, repeat each T) = returnTuple1()
124+
// expected-error@-1 {{'(T...)' is not convertible to '(x: Int, T...)', tuples have a different number of elements}}
125+
// expected-error@-2 {{generic parameter 'T' could not be inferred}}
101126

102-
let _: (y: repeat each T) = returnTupleLabel1() // expected-error {{type of expression is ambiguous without more context}}
103-
let _: (y: Int, repeat each T) = returnTupleLabel1() // expected-error {{type of expression is ambiguous without more context}}
127+
let _: (Int, x: repeat each T) = returnTuple2()
128+
// expected-error@-1 {{cannot convert value of type '(Int, T...)' to specified type '(Int, x: T...)'}}
129+
// expected-error@-2 {{generic parameter 'T' could not be inferred}}
104130

105-
let _: (x: repeat each T) = returnTupleLabel2() // expected-error {{type of expression is ambiguous without more context}}
106-
let _: (Int, y: String, repeat each T) = returnTupleLabel2() // expected-error {{type of expression is ambiguous without more context}}
131+
let _: (Int, x: String, repeat each T) = returnTuple2()
132+
// expected-error@-1 {{'(Int, T...)' is not convertible to '(Int, x: String, T...)', tuples have a different number of elements}}
133+
// expected-error@-2 {{generic parameter 'T' could not be inferred}}
107134

108-
let _: (repeat each T, y: Float) = returnTupleLabel3() // expected-error {{type of expression is ambiguous without more context}}
135+
let _: (y: repeat each T) = returnTupleLabel1()
136+
// expected-error@-1 {{cannot convert value of type '(x: T...)' to specified type '(y: T...)'}}
137+
// expected-error@-2 {{generic parameter 'T' could not be inferred}}
109138

110-
let _: (Int, String, repeat each T, x: Float) = returnTupleLabel3() // expected-error {{type of expression is ambiguous without more context}}
139+
let _: (y: Int, repeat each T) = returnTupleLabel1()
140+
// expected-error@-1 {{'(x: T...)' is not convertible to '(y: Int, T...)', tuples have a different number of elements}}
141+
// expected-error@-2 {{generic parameter 'T' could not be inferred}}
142+
143+
let _: (x: repeat each T) = returnTupleLabel2()
144+
// expected-error@-1 {{'(Int, x: T...)' is not convertible to '(x: T...)', tuples have a different number of elements}}
145+
// expected-error@-2 {{generic parameter 'T' could not be inferred}}
146+
147+
let _: (Int, y: String, repeat each T) = returnTupleLabel2()
148+
// expected-error@-1 {{'(Int, x: T...)' is not convertible to '(Int, y: String, T...)', tuples have a different number of elements}}
149+
// expected-error@-2 {{generic parameter 'T' could not be inferred}}
150+
151+
let _: (repeat each T, y: Float) = returnTupleLabel3()
152+
// expected-error@-1 {{'(Int, T..., y: Float)' is not convertible to '(T..., y: Float)', tuples have a different number of elements}}
153+
// expected-error@-2 {{generic parameter 'T' could not be inferred}}
154+
155+
let _: (Int, String, repeat each T, x: Float) = returnTupleLabel3()
156+
// expected-error@-1 {{'(Int, T..., y: Float)' is not convertible to '(Int, String, T..., x: Float)', tuples have a different number of elements}}
157+
// expected-error@-2 {{generic parameter 'T' could not be inferred}}
111158

112159
let _: (repeat each T, y: Float) = returnTupleLabel4() // expected-error {{'(Int, x: T..., y: Float)' is not convertible to '(T..., y: Float)', tuples have a different number of elements}}
113160
// expected-error@-1 {{generic parameter 'T' could not be inferred}}
114161

115162
let _: (Int, x: String, y: repeat each T) = returnTupleLabel4() // expected-error {{cannot convert value of type '(Int, x: String, y: Float)' to specified type '(Int, x: String, y: T...)'}}
116163

117-
let _: (Int, repeat each T, x: repeat each T) = returnTupleLabel5() // expected-error {{type of expression is ambiguous without more context}}
164+
let _: (Int, repeat each T, x: repeat each T) = returnTupleLabel5()
165+
// expected-error@-1 {{cannot convert value of type '(Int, T..., y: U...)' to specified type '(Int, T..., x: T...)'}}
166+
// expected-error@-2 {{generic parameter 'T' could not be inferred}}
167+
// expected-error@-3 {{generic parameter 'U' could not be inferred}}
118168

119-
let _: (repeat each T, y: Float, repeat each T) = returnTupleLabel5() // expected-error {{type of expression is ambiguous without more context}}
169+
let _: (repeat each T, y: Float, repeat each T) = returnTupleLabel5()
170+
// expected-error@-1 {{cannot convert value of type '(Int, T..., y: U...)' to specified type '(T..., y: Float, T...)'}}
171+
// expected-error@-2 {{generic parameter 'T' could not be inferred}}
172+
// expected-error@-3 {{generic parameter 'U' could not be inferred}}
120173

121174
let _: (repeat each T, y: Int) = returnTupleLabel6() // expected-error {{'(Int, x: T..., y: U...)' is not convertible to '(T..., y: Int)', tuples have a different number of elements}}
122175
// expected-error@-1 {{generic parameter 'T' could not be inferred}}

0 commit comments

Comments
 (0)