Skip to content

Commit 39e7c77

Browse files
committed
When generating constraints for subscript expressions, look beyond array
slice types when deciding whether or not to create a fresh type variable for the array's base expression. (rdar://problem/2639230)
1 parent ca97762 commit 39e7c77

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

lib/Sema/CSGen.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,8 +1193,12 @@ namespace {
11931193
baseTy = baseTy->getLValueOrInOutObjectType();
11941194
}
11951195

1196-
if (auto arraySliceTy = dyn_cast<ArraySliceType>(baseTy.getPointer())) {
1197-
baseTy = arraySliceTy->getDesugaredType();
1196+
if (CS.isArrayType(baseTy.getPointer())) {
1197+
1198+
if (auto arraySliceTy =
1199+
dyn_cast<ArraySliceType>(baseTy.getPointer())) {
1200+
baseTy = arraySliceTy->getDesugaredType();
1201+
}
11981202

11991203
auto indexExpr = subscriptExpr->getIndex();
12001204

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %target-parse-verify-swift
2+
3+
var fa2: Array<Double> = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
4+
print("six has the value [\(fa2[0]), \(fa2[1]), \(fa2[2]), \(fa2[3]), \(fa2[4]), \(fa2[5])]")
5+
6+
var threeDoubles = Array(repeating: 0.0, count: 3)
7+
var anotherThreeDoubles = Array(repeating: 2.5, count: 3)
8+
var sixDoubles: [Double] = threeDoubles + anotherThreeDoubles
9+
print("six has the value [\(sixDoubles[0]), \(sixDoubles[1]), \(sixDoubles[2]), \(sixDoubles[3]), \(sixDoubles[4]), \(sixDoubles[5])]")

0 commit comments

Comments
 (0)