Skip to content

Commit 9bf22d3

Browse files
authored
Merge pull request #8709 from slavapestov/misc-junk
Fix a bug found by inspection and add some regression tests
2 parents 1f7ec57 + 2281ff0 commit 9bf22d3

16 files changed

+127
-24
lines changed

lib/Sema/CSApply.cpp

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4748,31 +4748,10 @@ Expr *ExprRewriter::coerceExistential(Expr *expr, Type toType,
47484748
cs.getType(result)));
47494749
}
47504750

4751-
// If the type we are trying to coerce is a tuple, let's look through
4752-
// its elements to see if there are any LValue types present, such requires
4753-
// load or address-of operation first before proceeding with erasure.
4751+
// Load tuples with lvalue elements.
47544752
if (auto tupleType = fromType->getAs<TupleType>()) {
4755-
bool coerceToRValue = false;
4756-
for (auto element : tupleType->getElements()) {
4757-
if (element.getType()->is<LValueType>()) {
4758-
coerceToRValue = true;
4759-
break;
4760-
}
4761-
}
4762-
4763-
// Tuple has one or more LValue types associated with it,
4764-
// which requires coercion to RValue, let's perform it here by creating
4765-
// new tuple type with LValue(s) stripped off and coercing
4766-
// expression to that type, which would do required transformation.
4767-
if (coerceToRValue) {
4768-
SmallVector<TupleTypeElt, 2> elements;
4769-
for (auto &element : tupleType->getElements())
4770-
elements.push_back(TupleTypeElt(element.getType()->getRValueType(),
4771-
element.getName(),
4772-
element.getParameterFlags()));
4773-
4774-
// New type is guaranteed to be a tuple because source type is one.
4775-
auto toTuple = TupleType::get(elements, ctx)->castTo<TupleType>();
4753+
if (tupleType->isLValueType()) {
4754+
auto toTuple = tupleType->getRValueType()->castTo<TupleType>();
47764755
SmallVector<int, 4> sources;
47774756
SmallVector<unsigned, 4> variadicArgs;
47784757
bool failed = computeTupleShuffle(tupleType, toTuple,

test/Constraints/tuple.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,3 +202,14 @@ func f(a : r25271859<(Float, Int)>) {
202202
}
203203
}
204204

205+
// LValue to rvalue conversions.
206+
207+
func takesRValue(_: (Int, (Int, Int))) {}
208+
func takesAny(_: Any) {}
209+
210+
var x = 0
211+
var y = 0
212+
213+
let _ = (x, (y, 0))
214+
takesRValue((x, (y, 0)))
215+
takesAny((x, (y, 0)))
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: not --crash %target-swift-ide-test -code-completion -code-completion-token=A -source-filename=%s
2+
// REQUIRES: asserts
3+
4+
func matched<C: Collection>(atStartOf c: C)
5+
where C.Index#^A^# == Index {
6+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: not --crash %target-swift-ide-test -code-completion -code-completion-token=A -source-filename=%s
2+
// REQUIRES: asserts
3+
4+
let bounds: Range#^A^#
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: not --crash %target-swift-ide-test -code-completion -code-completion-token=A -source-filename=%s
2+
// REQUIRES: asserts
3+
4+
func searchTest(format: ()->String = { "" }#^A^#) {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: not --crash %target-swift-ide-test -code-completion -code-completion-token=A -source-filename=%s
2+
// REQUIRES: asserts
3+
4+
func _thread() {
5+
_ = #^A^#
6+
}
7+
8+
func run<InputCollection : Collection, Result>(_: InputCollection) -> Result {}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %target-swift-ide-test -code-completion -code-completion-token=A1 -source-filename=%s
2+
// RUN: %target-swift-ide-test -code-completion -code-completion-token=B1 -source-filename=%s
3+
// RUN: %target-swift-ide-test -code-completion -code-completion-token=C1 -source-filename=%s
4+
5+
// RUN: not --crash %target-swift-ide-test -code-completion -code-completion-token=A2 -source-filename=%s
6+
// RUN: not --crash %target-swift-ide-test -code-completion -code-completion-token=B2 -source-filename=%s
7+
// RUN: not --crash %target-swift-ide-test -code-completion -code-completion-token=C2 -source-filename=%s
8+
9+
// RUN: %target-swift-ide-test -code-completion -code-completion-token=A3 -source-filename=%s
10+
// RUN: not --crash %target-swift-ide-test -code-completion -code-completion-token=B3 -source-filename=%s
11+
// REQUIRES: asserts
12+
13+
class a1<b#^A1^#> {}
14+
struct a2<b#^B1^#> {}
15+
enum a3<b#^C1^#> {}
16+
17+
class a4<b> where c == b#^A2^# {}
18+
struct a5<b> where c == b#^B2^# {}
19+
enum a6<b> where c == b#^C2^# {}yt
20+
21+
func f1<b#^A3^#> {}
22+
func f2<b>() where c == b#^B3^# {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: not --crash %target-swift-ide-test -code-completion -code-completion-token=A -source-filename=%s
2+
// REQUIRES: asserts
3+
4+
protocol a {
5+
associatedtype b
6+
}
7+
protocol c {
8+
associatedtype d : a
9+
}
10+
11+
struct e<f : c> where f == f.g.b {
12+
#^A^#
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: not --crash %target-swift-ide-test -code-completion -code-completion-token=A -source-filename=%s
2+
// REQUIRES: asserts
3+
4+
class D<X, Y>() {}
5+
6+
class C<T> {
7+
func f<U>() -> D<U, T> {}
8+
func g() {
9+
f#^A^#
10+
}
11+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: not --crash %target-swift-ide-test -code-completion -code-completion-token=A -source-filename=%s
2+
// REQUIRES: asserts
3+
4+
.a != nil #^A^#
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: not --crash %target-swift-ide-test -code-completion -code-completion-token=A -source-filename=%s
2+
// REQUIRES: asserts
3+
4+
extension Integer {
5+
#^A^#
6+
extension {
7+
var : Self
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: not --crash %target-swift-ide-test -code-completion -code-completion-token=A -source-filename=%s
2+
// REQUIRES: asserts
3+
4+
Integer#^A^#
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: not --crash %target-swift-ide-test -code-completion -code-completion-token=A -source-filename=%s
2+
// REQUIRES: asserts
3+
4+
protocol a where #^A^#
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: not --crash %target-swift-ide-test -code-completion -code-completion-token=A -source-filename=%s
2+
// REQUIRES: asserts
3+
4+
func a<b>(() -> b) -> b {
5+
a {}#^A^#
6+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// RUN: %target-swift-ide-test -code-completion -code-completion-token=A -source-filename=%s
2+
3+
extension Integer {
4+
init() {
5+
self = #^A^#
6+
}
7+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %target-swift-ide-test -code-completion -code-completion-token=A -source-filename=%s
2+
3+
protocol MyDelegate: AnyObject {
4+
func mySweetDelegateFunction()
5+
}
6+
7+
class Foo {
8+
weak var delegate: MyDelegate?
9+
10+
func bar() {
11+
self.delegate.#^A^#
12+
// ^--- type "." here -> crash
13+
}
14+
}

0 commit comments

Comments
 (0)