Skip to content

Commit aff0f45

Browse files
authored
Merge pull request swiftlang#79026 from xedin/rdar-143474313
[CSBindings] Allow optional subtype inference when closure result is …
2 parents f5158f8 + c922ab5 commit aff0f45

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

lib/Sema/CSBindings.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -2596,7 +2596,8 @@ bool TypeVarBindingProducer::computeNext() {
25962596
// expression is non-optional), if we allow both the solver would
25972597
// find two solutions that differ only in location of optional
25982598
// injection.
2599-
if (!TypeVar->getImpl().isClosureResultType() || objTy->isVoid()) {
2599+
if (!TypeVar->getImpl().isClosureResultType() || objTy->isVoid() ||
2600+
objTy->isTypeVariableOrMember()) {
26002601
// If T is a type variable, only attempt this if both the
26012602
// type variable we are trying bindings for, and the type
26022603
// variable we will attempt to bind, both have the same

test/Constraints/argument_matching.swift

-4
Original file line numberDiff line numberDiff line change
@@ -1488,19 +1488,15 @@ func trailingclosure4(f: () -> Int) {}
14881488
trailingclosure4 { 5 }
14891489

14901490
func trailingClosure5<T>(_ file: String = #file, line: UInt = #line, expression: () -> T?) { }
1491-
// expected-note@-1 {{in call to function 'trailingClosure5(_:line:expression:)'}}
14921491
func trailingClosure6<T>(value: Int, expression: () -> T?) { }
1493-
// expected-note@-1 {{in call to function 'trailingClosure6(value:expression:)'}}
14941492

14951493
trailingClosure5(file: "hello", line: 17) { // expected-error{{extraneous argument label 'file:' in call}}{{18-24=}}
1496-
// expected-error@-1 {{generic parameter 'T' could not be inferred}}
14971494
return Optional.Some(5)
14981495
// expected-error@-1 {{enum type 'Optional<Wrapped>' has no case 'Some'; did you mean 'some'?}} {{19-23=some}}
14991496
// expected-error@-2 {{generic parameter 'Wrapped' could not be inferred}}
15001497
// expected-note@-3 {{explicitly specify the generic arguments to fix this issue}}
15011498
}
15021499
trailingClosure6(5) { // expected-error{{missing argument label 'value:' in call}}{{18-18=value: }}
1503-
// expected-error@-1 {{generic parameter 'T' could not be inferred}}
15041500
return Optional.Some(5)
15051501
// expected-error@-1 {{enum type 'Optional<Wrapped>' has no case 'Some'; did you mean 'some'?}} {{19-23=some}}
15061502
// expected-error@-2 {{generic parameter 'Wrapped' could not be inferred}}

test/Constraints/closures.swift

+21
Original file line numberDiff line numberDiff line change
@@ -1305,3 +1305,24 @@ do {
13051305
})
13061306
}
13071307
}
1308+
1309+
// rdar://143474313 - invalid error: member 'init(item:)' in 'Test.Item?' produces result of type 'Test.Item', but context expects 'Test.Item?'
1310+
do {
1311+
struct List {
1312+
struct Item {
1313+
}
1314+
1315+
var items: [Item] = []
1316+
}
1317+
1318+
struct Test {
1319+
struct Item {
1320+
init(item: List.Item) {
1321+
}
1322+
}
1323+
1324+
let list: List
1325+
1326+
var items: [Test.Item] { .init(list.items.compactMap { .init(item: $0) }) } // Ok
1327+
}
1328+
}

validation-test/Sema/type_checker_perf/fast/rdar22079400.swift renamed to validation-test/Sema/type_checker_perf/slow/rdar22079400.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %target-typecheck-verify-swift -solver-expression-time-threshold=1
22
// REQUIRES: tools-release,no_asan
33

4-
let _ = (0...1).lazy.flatMap {
4+
let _ = (0...1).lazy.flatMap { // expected-error {{reasonable time}}
55
a in (1...2).lazy.map { b in (a, b) }
66
}.filter {
77
1 < $0 && $0 < $1 && $0 + $1 < 3

0 commit comments

Comments
 (0)