Hi,
I got a build error "Generic parameter 'T' could not be inferred" for the
following code.
Can anyone explain why we can't use a protocol to infer the generic type T?
class Emitter {
func emit<T: Emittable>() -> T {
...
}
}
protocol Emittable {}
protocol Subemittable: Emitable {}
class ConcreteEmittable: Subemittable {}
func testCode() {
let emitter = Emitter()
// Error: Generic parameter 'T' could not be inferred
let _: Emittable = emitter.emit()
// Error: Generic parameter 'T' could not be inferred
let _: Subemittable = emitter.emit()
// This works
let _: ConcreteEmittable = emitter.emit()
}
Thanks,
Satoshi
_______________________________________________
swift-users mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-users