Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

This is a general question with a specific example.

How do people getting into scala and using it for big projects handle unreliability of tools/IDE? Do you just accept red markings all over your source code?

I encounter yet another scala codebase where working code is flagged red by idea Cannot resolve symbol Repr.

I start a playground project to explore one of libraries in the codebase - shapeless (as I understand it a highly regarded library in scala community).

I write extremely basic code from the first page of official shapeless guide.

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) and gen(1) are flagged with No implicits found for parameter at hlist.At[String :: Boolean :: HNil, Nat#N]

The code works.

I also remember errors-but-not-real-errors being caused by Akka HTTP.

like image 211
John H Avatar asked Jun 09 '20 14:06

John H


People also ask

How do I change the Scala version in Intellij?

 In most cases your project JDK is not compatible with Scala or sbt version, try to change the Scala Compile Server SDK. Press Ctrl+Alt+S to open Settings/Preferences dialog. From the options on the left, select Build, Execution, Deployment | Compiler | Scala | Scala Compiler Server.

How do I add Scala framework support in Intellij?

To add Scala support to existing module:Right-click the module in Project View, choose “Add Framework Support…” Check “Scala” in technologies list (unavailable if module has Scala facet attached) Provide a path to Scala installation (if not detected)

How do I create a Scala project in Intellij?

Delegate a Scala project build to sbtPress Ctrl+Alt+S to open the IDE settings and select Build, Execution, Deployment | Build Tools | sbt. In the sbt projects section, select a project for which you want to configure build actions. In the sbt shell section, select the builds option. Click OK to save the changes.

What IDE’s are available for Scala?

For scala also we have many different IDE available where we can edit our code and make it work the way we want. We have a list of different IDE’s available in the market to edit our code. If we talk about Java the most popular editor we have is eclipse and intellij.

How to update Scala IDE in Eclipse without JDK?

Note: If you do not have JDK installed, you may get them from this link. Step 1: Open the eclipse and click on the “Help” and select “Install New Software” Step 2: Now click the “Add” button to add the new repository. Step 3: Add Scala IDE update site, You can use the most recent Scala update site

Why can’t I compile my Scala project?

Why am I unable to compile my Scala project? In most cases your project JDK is not compatible with Scala or sbt version, try to change the Scala Compile Server SDK. Press Ctrl+Alt+S to open Settings/Preferences dialog. From the options on the left, select Build, Execution, Deployment | Compiler | Scala | Scala Compiler Server.

How to set up Scala in IntelliJ?

After setting up java, we can open the Intellij idea and set the version of java we want to use for the specific project. Now open intellij and download the plugin for Scala form market place. Go to file >> settings >> then search for scala plugin and type scala into it.


1 Answers

There seems to be a fundamental difficulty in IntelliJ supporting libraries relying on macros such as 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.


You could try reporting highlighting errors as a bug at

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

Here is an example you could use as a template

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

Select the affected subsystem as Error Highlighting

This feature is called Type-aware highlighting and can be disabled by clicking on the little T icon in bottom right corner

enter image description here

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:

like image 125
Mario Galic Avatar answered Oct 18 '22 09:10

Mario Galic