Skip to content

Commit 37477b3

Browse files
authored
Merge pull request #67915 from xedin/rdar-113745963
Revert "[CSBindings] Prefer conjunctions over closure variables without bindings"
2 parents b68e5f6 + cfea0d3 commit 37477b3

File tree

4 files changed

+63
-93
lines changed

4 files changed

+63
-93
lines changed

lib/Sema/CSBindings.cpp

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,13 +1094,6 @@ bool BindingSet::favoredOverConjunction(Constraint *conjunction) const {
10941094
if (locator->directlyAt<ClosureExpr>()) {
10951095
auto *closure = castToExpr<ClosureExpr>(locator->getAnchor());
10961096

1097-
// If there are no bindings for the closure yet we cannot prioritize
1098-
// it because that runs into risk of missing a result builder transform.
1099-
if (TypeVar->getImpl().isClosureType()) {
1100-
if (Bindings.empty())
1101-
return false;
1102-
}
1103-
11041097
if (auto transform = CS.getAppliedResultBuilderTransform(closure)) {
11051098
// Conjunctions that represent closures with result builder transformed
11061099
// bodies could be attempted right after their resolution if they meet
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// RUN: %target-typecheck-verify-swift
2+
3+
// rdar://113745963
4+
5+
// https://github.com/apple/swift/pull/67441 changed closure resolution order which makes the following code fail to type-check.
6+
7+
struct Date : Equatable {
8+
static var distantPast = Date()
9+
}
10+
11+
enum Request {
12+
struct Options: OptionSet {
13+
static let option1 = Options(rawValue: 1 << 0)
14+
static let option2 = Options(rawValue: 1 << 1)
15+
16+
let rawValue: Int
17+
18+
init(rawValue: Int) {
19+
self.rawValue = rawValue
20+
}
21+
}
22+
23+
enum Source : Comparable {
24+
case automatic
25+
case manual(Date)
26+
27+
static func < (lhs: Source, rhs: Source) -> Bool { true }
28+
}
29+
30+
case problem(options: Options, source: Source)
31+
}
32+
33+
enum OuterSource {
34+
case automatic, manual, unknown
35+
}
36+
37+
struct Test {
38+
func test(arr: [Int]) {
39+
let _: [Request] = arr.map { value in
40+
let source: OuterSource = .automatic
41+
let dateAdded = Date.distantPast
42+
return .problem(
43+
options: {
44+
switch source {
45+
case .automatic:
46+
return [.option1, .option2]
47+
case .manual, .unknown:
48+
return []
49+
}
50+
}(),
51+
source: {
52+
switch source {
53+
case .manual:
54+
return .manual(dateAdded)
55+
case .automatic, .unknown:
56+
return .automatic
57+
}
58+
}())
59+
}
60+
}
61+
}

test/Constraints/issue67363.swift

Lines changed: 0 additions & 85 deletions
This file was deleted.

test/expr/closure/multi_statement.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,8 @@ func test_result_builder_in_member_chaining() {
713713
Test.test {
714714
let test = Test()
715715
return test
716-
}.builder { // Ok
716+
// FIXME: This call should type-check, currently closure is resolved before overload of `builder` is picked.
717+
}.builder { // expected-error {{cannot convert value of type '()' to closure result type 'Int'}}
717718
let result = ""
718719
result
719720
}

0 commit comments

Comments
 (0)