以下简单程序无法在现成的scala 2.12和无形状的2.3.2下编译:
import shapeless.Generic
object InferGeneric {
class WithGeneric[T](implicit ev: Generic[T])
case class Impl() {}
object Impl extends WithGeneric[Impl]
}
编译器抛出以下错误:
/.../InferGeneric.scala:11: super constructor cannot be passed a self reference unless parameter is declared by-name
object Impl extends WithGeneric[Impl]
有趣的是,重命名object Impl
后,它可以毫无问题地进行编译。与通用对象结合使用时,通用推理中使用的宏似乎会导致某些循环解析。如何避免这种情况?
非常感谢您的意见!
问题是由宏生成的代码,但是它并不是特定于宏的。您可以使用明确定义的实例重现该问题: