False errors when using cats library in IntelliJ

微笑、不失礼 提交于 2019-12-09 08:46:19

问题


I am using the cats Scala library and the IntelliJ IDE seems to be struggling with the use of implicits:

Here is a simple example:

import cats.std.all._
import cats.Traverse.ops._

def useSequence[A](ls : List[Option[A]]) : Option[List[A]] = {
  ls.sequence
}

In IntelliJ, this code is highlighted red. But I can build just fine using Make Project or the command line.

Right now the error is:

Expression of type Nothing[List[Nothing]] doesn't conform to expected type Option[List[A]]

Other times the error is something like:

value sequence is not a member of List[Option[A]]

Is this a bug in IntelliJ or am I missing some configuration?

I am using IntelliJ 15.0.2 with version 2.0.4 of the Scala plugin.


回答1:


This is an open issue in IntelliJ/Scala Plugin (SCL-10259 - False error (good code red): sequence from cats) open since May 13, 2016.

As @Noah comments above, the workaround for now is to help IntelliJ out by providing the types of the container and contained types that sequence is applied to, i.e. (updated for cats 1.0):

import cats.instances.all._
import cats.Traverse.ops._

def useSequence[A](ls : List[Option[A]]) : Option[List[A]] = 
  ls.sequence[Option, A]


来源:https://stackoverflow.com/questions/34695616/false-errors-when-using-cats-library-in-intellij

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!