scala 开发人员如何处理带有 shapeless 的 scala 代码中不正确的 IDE(Idea) 错误

How do scala developers cope with incorrect IDE(Idea) errors in scala code with shapeless

这是一个带有具体示例的一般性问题。

人们如何进入 scala 并将其用于大型项目来处理 tools/IDE 的不可靠性?您是否只接受整个源代码中的红色标记?

我遇到了另一个 scala 代码库,其中工作代码被想法标记为红色 Cannot resolve symbol Repr

我开始了一个 playground 项目来探索代码库中的一个库 - shapeless(据我所知,它是 scala 社区中备受推崇的库)。

我从官方无形指南的第一页开始编写非常基本的代码。

package example
import shapeless._

object Hello extends App {
  val genericEmployee = Generic[Employee].to(Employee("Dave", isOld = true))
  val genericIceCream = Generic[IceCream].to(IceCream("yellow", isInCone = false))

  def genericCsv (gen: String :: Boolean :: HNil) :List[String] = List(gen(0), gen(1).toString())

  println(genericCsv(genericIceCream).toString())
}

case class Employee (name: String, isOld: Boolean)

case class IceCream (name: String, isInCone: Boolean)

gen(0)gen(1) 标记为 No implicits found for parameter at hlist.At[String :: Boolean :: HNil, Nat#N]

代码有效。

我还记得错误,但不是真正的错误是由 Akka HTTP 引起的。

IntelliJ 支持依赖于 shapeless 等宏的库似乎存在根本性困难

@niktrop

Shapeless is heavily using macros. We have no way to support them generically.

@joroKr21

there is a fundamental barrier for whitebox macros. You have to run a complete typecheck and expand them just to see what type they return and this is not feasible to do on every keystroke. Blackbox macros on the other hand shouldn't pose such problems.

@olafurpg

scala-compiler and intellij-scala are different typecheckers, scala-reflect macros are currently implemented against scala-compiler APIs which makes them difficult to support in alternative scala compilers.


您可以尝试将突出显示错误报告为 bug at

https://youtrack.jetbrains.com/issues/SCL

这是您可以用作模板的示例

https://youtrack.jetbrains.com/issue/SCL-16091

Select 受影响的子系统为 Error Highlighting

此功能称为 Type-aware highlighting,可以通过单击右下角的 T 小图标来禁用

How to deal with false errors?

So, the truth is you have to remember that sometimes there’s no spoon error. To help us to fix a highlighting glitch you may report it to YouTrack as usual or by pressing Alt+Enter on wrong highlight: