Sourcery
Sourcery copied to clipboard
Sourcery doesn't properly work when using protocols with primary associated types
Sourcery doesn't seem to be able to properly generate code when using protocols with primary associated types. The problem arises when you have a protocol
that inherits from another protocol
with primary associated types, using an argument type for the inherited protocol:
protocol BaseProtocol<Element> {
associatedtype Element
var elements: Array<Element> { get }
}
// sourcery:AutoMockable
protocol ChildProtocol: BaseProtocol<String> {
var count: Int { get }
}
Running this with the standard mock template produces the following output, missing the elements
property defined in the parent protocol
:
class ChildProtocolMock: ChildProtocol {
var count: Int {
get { return underlyingCount }
set(value) { underlyingCount = value }
}
var underlyingCount: (Int)!
}
The problem seems to be related with the inheritance clause. If you instead declare the second protocol in the following way:
protocol ChildProtocol: BaseProtocol where Element == String {
var count: Int { get }
}
you get the following output, now including the property defined in the parent protocol
:
class ChildProtocolMock: ChildProtocol {
var count: Int {
get { return underlyingCount }
set(value) { underlyingCount = value }
}
var underlyingCount: (Int)!
var elements: Array<Element> = []
}
👋 Hello @jgongo ;
thank you very much for a detailed description and for filing the issue!
Nice find, should be easy to fix for 2.1.8 release.
As of the latest master
branch, I cannot reproduce this bug. Might have been resolved as a consequence.