Merge pull request #79026 from xedin/rdar-143474313

[CSBindings] Allow optional subtype inference when closure result is …
This commit is contained in:
Pavel Yaskevich
2025-01-30 00:37:46 -08:00
committed by GitHub
4 changed files with 24 additions and 6 deletions

View File

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

View File

@@ -1488,19 +1488,15 @@ func trailingclosure4(f: () -> Int) {}
trailingclosure4 { 5 }
func trailingClosure5<T>(_ file: String = #file, line: UInt = #line, expression: () -> T?) { }
// expected-note@-1 {{in call to function 'trailingClosure5(_:line:expression:)'}}
func trailingClosure6<T>(value: Int, expression: () -> T?) { }
// expected-note@-1 {{in call to function 'trailingClosure6(value:expression:)'}}
trailingClosure5(file: "hello", line: 17) { // expected-error{{extraneous argument label 'file:' in call}}{{18-24=}}
// expected-error@-1 {{generic parameter 'T' could not be inferred}}
return Optional.Some(5)
// expected-error@-1 {{enum type 'Optional<Wrapped>' has no case 'Some'; did you mean 'some'?}} {{19-23=some}}
// expected-error@-2 {{generic parameter 'Wrapped' could not be inferred}}
// expected-note@-3 {{explicitly specify the generic arguments to fix this issue}}
}
trailingClosure6(5) { // expected-error{{missing argument label 'value:' in call}}{{18-18=value: }}
// expected-error@-1 {{generic parameter 'T' could not be inferred}}
return Optional.Some(5)
// expected-error@-1 {{enum type 'Optional<Wrapped>' has no case 'Some'; did you mean 'some'?}} {{19-23=some}}
// expected-error@-2 {{generic parameter 'Wrapped' could not be inferred}}

View File

@@ -1305,3 +1305,24 @@ do {
})
}
}
// rdar://143474313 - invalid error: member 'init(item:)' in 'Test.Item?' produces result of type 'Test.Item', but context expects 'Test.Item?'
do {
struct List {
struct Item {
}
var items: [Item] = []
}
struct Test {
struct Item {
init(item: List.Item) {
}
}
let list: List
var items: [Test.Item] { .init(list.items.compactMap { .init(item: $0) }) } // Ok
}
}

View File

@@ -1,7 +1,7 @@
// RUN: %target-typecheck-verify-swift -solver-expression-time-threshold=1
// REQUIRES: tools-release,no_asan
let _ = (0...1).lazy.flatMap {
let _ = (0...1).lazy.flatMap { // expected-error {{reasonable time}}
a in (1...2).lazy.map { b in (a, b) }
}.filter {
1 < $0 && $0 < $1 && $0 + $1 < 3