mirror of
https://github.com/apple/swift.git
synced 2026-06-20 15:42:51 +02:00
9ea7587a3f
The TypeExpansionContext of a function that emits a reabstraction thunk might differ from the TypeExpansionContext of the thunk itself. This seems to cause a problem in one case at least, when emitting a function conversion from () -> some P to () -> any P where we can see the underlying type of the some P, we end up with a mismatch where the SIL type of the value was unwrapped, but the lowering of the formal type in the context of the thunk remains an opaque archetype. One of the examples in the test was uncovered by binding inference changes producing a different but equivalent constraint system solution, but the remaining cases were already broken prior. My change here is just a horrible workaround for this mismatch; the representational problem needs to be addressed properly elsewhere. Fixes rdar://172130660.
45 lines
671 B
Swift
45 lines
671 B
Swift
// RUN: %target-swift-emit-silgen %s
|
|
|
|
func f0<V>(_: () -> any P<V>) {}
|
|
func f1<V>(_: V.Type, _: () -> any P<V>) {}
|
|
func f2<V>(_: (V) -> (), _: () -> any P<V>) {}
|
|
|
|
protocol P<A> {
|
|
associatedtype A
|
|
}
|
|
|
|
struct G<A>: P {}
|
|
|
|
func g1() -> some P<Int> {
|
|
return G<Int>()
|
|
}
|
|
|
|
class B {}
|
|
class C: B {}
|
|
class D: C, P {
|
|
typealias A = Bool
|
|
}
|
|
|
|
func g2() -> some C & P {
|
|
return D()
|
|
}
|
|
|
|
func g3() -> (some P<Bool>, some C & P) {
|
|
return (G<Bool>(), D())
|
|
}
|
|
|
|
func test() {
|
|
let _: () -> any P<Int> = g1
|
|
let _: () -> B = g2
|
|
let _: () -> (any P, B) = g3
|
|
|
|
f0(g1)
|
|
f1(Int.self, g1)
|
|
f2({ $0 as Int }, g1)
|
|
|
|
f0({ g1() })
|
|
f1(Int.self, { g1() })
|
|
f2({ $0 as Int }, { g1() })
|
|
}
|
|
|