Cuckoo
Cuckoo copied to clipboard
Uncompilable DefaultImpl for generic functions in protocols with associated types
This is probably a sorta niche use case, but I actually encountered an issue with this in one of my codebases.
A minimal reproduction:
protocol GenericProtocol {
associatedtype V
func genericParameter<T>(value: T)
}
currently produces a DefaultImpl class that doesn't compile:
...
class DefaultImplCaller: GenericProtocol, @unchecked Sendable {
private let reference: Any
init<_CUCKOO$$GENERIC: GenericProtocol>(from defaultImpl: UnsafeMutablePointer<_CUCKOO$$GENERIC>, keeping reference: @escaping @autoclosure () -> Any?) where _CUCKOO$$GENERIC.V == V {
self.reference = reference
_storage$1$genericParameter = defaultImpl.pointee.genericParameter // error: Generic parameter 'T' could not be inferred
}
private let _storage$1$genericParameter: (T) -> Void // error: Cannot find type 'T' in scope
func genericParameter<T> (value p0: T) {
return _storage$1$genericParameter(p0)
}
}
...
I had to fight with the compiler a bit, but I managed to figure out a fix. I'll be opening up a PR soon, but I just wanted to open up an issue to link to first.
This hit me as well, it hurts my soul a little that there's an unmerged solution. Hopefully maintainers can prioritize it. Thanks @Brennanium for solving it.