在IntelliJ中使用cats库时出现错误 [英] False errors when using cats library in IntelliJ

查看:212
本文介绍了在IntelliJ中使用cats库时出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用猫Scala库,IntelliJ IDE似乎在使用implicits时遇到困难:

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

这是一个简单的例子:

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

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

在IntelliJ中,此代码以红色突出显示。但我可以使用 Make Project 或命令行来构建。

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

现在错误是:


Nothing类型的表达式[List [Nothing]]不符合预期类型选项[List [A]]

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

其他时间错误类似于:


值序列是不是列表的成员[选项[A]]

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

这是IntelliJ中的错误还是我错过了一些配置?

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

我使用的是IntelliJ 15.0.2和Scala插件的2.0.4版。

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

推荐答案

这是IntelliJ / Scala插件中的一个未解决的问题( SCL-10259 - 错误错误(好的代码红色):来自猫的序列)自2016年5月13日开始。

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

正如上面的@Noah评论,现在的解决方法是帮助IntelliJ输出通过提供conta的类型应用序列的iner和包含的类型,即(为猫1.0更新)

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]

这篇关于在IntelliJ中使用cats库时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆