当使用shapeless.Generic时,如何避免错误:除非通过名称声明参数,否则无法将超级构造函数传递给自引用?

问题描述 投票:3回答:1

以下简单程序无法在现成的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后,它可以毫无问题地进行编译。与通用对象结合使用时,通用推理中使用的宏似乎会导致某些循环解析。如何避免这种情况?

非常感谢您的意见!

scala implicit shapeless
1个回答
0
投票

问题是由宏生成的代码,但是它并不是特定于宏的。您可以使用明确定义的实例重现该问题:

© www.soinside.com 2019 - 2024. All rights reserved.