Open shivatinker opened 3 months ago
Simplified reproduction without arrays and optionals:
protocol Base {}
protocol MyArray<Element> {
associatedtype Element
var first: Element { get }
}
extension MyArray {
var first: Element { fatalError() }
}
struct Impl<Element>: MyArray {
var first: Element { fatalError() }
}
func foo(_ value: some Base) {}
func bar(a: Impl<any Base>) {
foo(a.first) // <-- Type 'any Base' cannot conform to 'Base'
}
first
must be defined both as protocol requirement and in extension as default implementation.
A bit simpler:
protocol P {}
extension P {
var p: any P { get {} }
}
struct S: P {
var p: any P { get {} }
}
func foo(_: some P) {}
func test(s: S) {
foo(s.p)
}
Description
I have found a case, where existential type is not implicitly opened upon passing in a generic function. Strangely enough, passing it through an intermediate variable fixes the issue.
Reproduction
However,
works.
Expected behavior
Existential should be opened in
foo(things.first!)
implicitly.Environment
Additional information
https://forums.swift.org/t/strange-compiler-behaviour-in-implicitly-opened-existentials/72916
P.S. If you will find this issue easy-looking, I may attempt to try to fix it.