mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Currently solver picks the first conjunction it can find, which means - the earliest resolved closure. This is not always correct because when calls are chained closures passed to the lower members could be resolved sooner than the ones higher up but at the same time they depend on types inferred from members higher in the chain. Let's make sure that multi-statement closures are always solved in order they appear in the AST to make sure that types are available to members lower in the chain.
32 lines
517 B
Swift
32 lines
517 B
Swift
// RUN: %target-typecheck-verify-swift
|
|
|
|
protocol P {
|
|
func isEqual(_ other: P) -> Bool
|
|
}
|
|
|
|
struct A {
|
|
var value: P? = nil
|
|
}
|
|
|
|
struct B {
|
|
func foo() throws -> A {}
|
|
}
|
|
|
|
struct E {
|
|
func getB(_ flag: inout Bool) throws -> B {
|
|
return B()
|
|
}
|
|
}
|
|
|
|
func foo(arr: [E], other: P) -> Bool {
|
|
return arr.compactMap { i in
|
|
var flag = false
|
|
return try? i.getB(&flag)
|
|
}.compactMap { u -> P? in // Ok
|
|
guard let a = try? u.foo() else { return nil }
|
|
return a.value!
|
|
}.contains {
|
|
$0.isEqual(other)
|
|
}
|
|
}
|