If I have the contents of an object imported at the top of a Scala worksheet in Intellij, when I add new things to the object, they cannot be found in the worksheet. Even after I build the project and reevaluate the worksheet, it can't find the new property. Autocomplete works. If I quit and restart IntelliJ it works.
This is the error:
java.lang.NoSuchMethodError: Arith$.foo()Ljava/lang/String;
at #worksheet#.get$$instance$$res6(ArithWS.sc:15)
at A$A1$.main(ArithWS.sc:41)
at #worksheet#.#worksheet#(ArithWS.sc)
Weirdly, it seems to compile, but fails at runtime. This is a normal SBT project. IntelliJ 2017.2.5, Scala 2.12.3. Selecting the "Make project" checkbox doesn't help. Actually no combination of checkboxes makes it work. No amount of rebuilding the project or the worksheet helps either. Only restarting IntelliJ will get the worksheet to pick up the new code.
Example project code in Arith.scala:
object Arith {
val foo = "foo"
}
Example worksheet ArithWS.sc:
import Arith._
foo
To install Scala plugin, press Ctrl+Alt+S , open the Plugins page, browse repositories to locate the Scala plugin, click Install and restart IntelliJ IDEA. Now you can successfully check out from VCS, create, or import Scala projects.
This seems to fix it, though I would love to know why the default setting is broken, or what this undocumented setting does: Go to File -> Settings -> Languages & Frameworks -> Scala -> Worksheet (tab) . Unselect "Run worksheet in the compiler process".
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With