Skip to content

Commit 8d9f97c

Browse files
committed
Fix another subtle SE-0110-related break.
The change to roll back a part of SE-0110 to allow multi-argument functions to be passed in places where functions taking a tuple are expected resulted in a regression in some cases where the fix would strip off the last ParenType from single-argument functions. Instead of stripping off parens from both function types we're trying to match when they both have them, strip off none. This ensures that we don't get summarily rejected in the nested matchTypes call by other SE-0110-related code that bails if the two types do not have the same "parenness". Fixes rdar://problem/33043106 / SR-5387.
1 parent b89b570 commit 8d9f97c

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,9 +1082,8 @@ ConstraintSystem::matchFunctionTypes(FunctionType *func1, FunctionType *func2,
10821082
if (auto elt = locator.last()) {
10831083
if (elt->getKind() == ConstraintLocator::ApplyArgToParam) {
10841084
if (auto *paren2 = dyn_cast<ParenType>(func2Input.getPointer())) {
1085-
func2Input = paren2->getUnderlyingType();
1086-
if (auto *paren1 = dyn_cast<ParenType>(func1Input.getPointer()))
1087-
func1Input = paren1->getUnderlyingType();
1085+
if (!isa<ParenType>(func1Input.getPointer()))
1086+
func2Input = paren2->getUnderlyingType();
10881087
}
10891088
}
10901089
}

test/Constraints/tuple_arguments.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1551,3 +1551,26 @@ extension Sequence where Iterator.Element == (key: String, value: String?) {
15511551
}
15521552
}
15531553
}
1554+
1555+
func rdar33043106(_ records: [(Int)], _ other: [((Int))]) -> [Int] {
1556+
let x: [Int] = records.flatMap { _ in
1557+
let i = 1
1558+
return i
1559+
}
1560+
let y: [Int] = other.flatMap { _ in
1561+
let i = 1
1562+
return i
1563+
}
1564+
1565+
return x + y
1566+
}
1567+
1568+
func itsFalse(_: Int) -> Bool? {
1569+
return false
1570+
}
1571+
1572+
func rdar33159366(s: AnySequence<Int>) {
1573+
_ = s.flatMap(itsFalse)
1574+
let a = Array(s)
1575+
_ = a.flatMap(itsFalse)
1576+
}

validation-test/compiler_crashers_2_fixed/0111-rdar33067102.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not %target-swift-frontend -swift-version 4 %s -typecheck
1+
// RUN: %target-swift-frontend -swift-version 4 %s -typecheck
22

33
func flatterMap(_ records: [(Int)]) -> [Int] {
44
records.flatMap { _ in return 1 } // expected-note {{}}

0 commit comments

Comments
 (0)