【发布时间】:2019-12-18 23:44:48
【问题描述】:
我正在尝试实现一个宏,它返回类XX 的子类型,类型参数T。明显的实现无法编译,可能是因为 Scala 弱类型推断。
小例子:
def foo[T, X <: XX[T]](x: X): X = macro fooMacro[T, X]
def fooMacro[T, X<: XX[T]](c: Context)(x: c.Expr[X]): c.Expr[X] = ...
错误信息:
Error:(9, 11) macro implementation has incompatible shape: ...
type arguments [Nothing,X] do not conform to method fooMacro type parameter bounds [T,X<: XX[T]]>
是否可以解决这个问题?
【问题讨论】:
标签: scala generics type-inference scala-macros