Sourcery
Sourcery copied to clipboard
The generic type is not recognized correctly
struct TestGeneric<T>: JSONDictionaryConvertible where T: JSONDictionaryConvertible {
let name: String
let haha: T
}
variable haha conforms protocol JSONDictionaryConvertible but variable haha's type.implements do not include JSONDictionaryConvertible
Had the same issue, as a workaround I added this to my stencil to get the class / struct generic conformance, definitely not perfect, but it works. Hope this helps you forward :)
{% macro fullAssociatedTypes type %}{% for _, baseType in type.basedTypes where forloop.first %}{% if baseType.associatedTypes %}<{% for _, baseType in type.basedTypes %}{% if not forloop.first %}, {% endif %}{% for _, associatedType in baseType.associatedTypes %}{% if not forloop.first %}, {% endif %}{{ associatedType.name }}: {{ associatedType.typeName.name }}{% endfor %}{% endfor %}>{% endif %}{% endfor %}{% endmacro %}
{% macro shortAssociatedTypes type %}{% for _, baseType in type.basedTypes where forloop.first %}{% if baseType.associatedTypes %}<{% for _, baseType in type.basedTypes %}{% if not forloop.first %}, {% endif %}{% for _, associatedType in baseType.associatedTypes %}{% if not forloop.first %}, {% endif %}{{ associatedType.name }}{% endfor %}{% endfor %}>{% endif %}{% endfor %}{% endmacro %}
{% for type in types.classes %}
struct {{ type.name }}Adapter{% call fullAssociatedTypes type %} {
let adaptee: {{ type.name }}{% call shortAssociatedTypes type %}
}
{% endfor %}
I should also mention that I only tested this with generic conformance on the left side like this and I haven't tested it on your code yet
struct TestGeneric<T: JSONDictionaryConvertible>: JSONDictionaryConvertible { }
👋🏻 Hello,
confirmed the bug, minimal reproducible:
template:
{% for struct in types.structs %}
{% for variable in struct.variables where variable.type.implements.AutoHashable %}
{{ variable.name }}
{% endfor %}
{% endfor %}
input
protocol AutoHashable {}
/// General protocol
protocol AutoHashableProtocol: AutoHashable {
var width: Double { get }
var height: Double { get}
static var name: String { get }
}
struct Testy: AutoHashableProtocol {
var width: Double
var height: Double
static var name: String { "" }
let name: String
}
struct TestGeneric<T>: AutoHashable where T: AutoHashable {
let name: String
let haha: T
var hoho: Testy
}
Expected Output | Actual Output |
---|---|
haha, hoho |
hoho |