How do I disable IntelliJ IDEA's type inspection?

匿名 (未验证) 提交于 2019-12-03 08:59:04

问题:

IntelliJ IDEA's Scala plugin many times complains about "type mismatch" even though the code in question compiles absolutely fine. I find this quite irritating, and would like to disable this feature. I didn't find any relevant option on searching in the settings. How do I get rid of it?

回答1:

Switching off 'Type Aware Highlighting' by clicking this symbol may help a bit.

Edit

There are also a number of Scala specific inspections which can be enabled and disabled. These can be accessed by clicking on the 'Inspector' icon (just to the left of the 'Type Aware' icon) shown in the first screenshot above and clicking 'configure inspections on the pop-up dialog.



回答2:

You can completely turn off error highlighting by clicking the little man with a bowler hat at the bottom-right hand corner of the screen and choosing "None" for Highlighting Level. But then you lose all error highlighting, not just the one that is annoying you. (Sorry, StackOverflow won't let me post an image to show exactly where to find "Hector the Inspector!)



回答3:

There seems a way to disable type aware highlighting just for a region of Scala code in IntelliJ. This was mentioned by a JetBrains developer in SCL-10983, later I found a documentation in Working with Type-Aware Highlighting.

Let us take following code (intentionally plain wrong):

class Data {   /*_*/   def data: Int = this   /*_*/   def dataAgain: Int = this } 

Only the second error will be highlighted in red, the first one enclosed in /*_*/ will be ignored.



回答4:

@rxg: Here is a small test case to demonstrate the problem:

rows is of type IndexedSeq[Row] where Row is from Apache POI's Excel library. traverse if a function from Scalaz. Validation is a data structure from Scalaz. GryphonError is an ADT from our codebase.

rows.zipWithIndex.traverse[({type L[X] = Validation[Seq[GryphonError], X]})#L, Seq[Any]] { case (row, r) =>   // some stuff } 

scalac compiles this code fine. IDEA's type-inspector complains:

   Type mismatch, expected: ((Row, Int) => F[B])                   actual:   ((Row, Int) => F[IndexedSeq[B]]) 


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