Files
swift-mirror/validation-test/compiler_crashers_2_fixed/0186-rdar46497155.swift
Pavel Yaskevich 65e7eec62f [CSSolver] Solve multi-statement closures in source order
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.
2022-12-12 10:57:21 -08:00

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)
}
}