Intellij Worksheet Scala Version

437 Views Asked by At

I have an sbt project with Scala 2.12.12.

Working with the worksheet (REPL), i decided to check the Scala version, and typed the following:

util.Properties.versionString

To my surprise i got

res7: String = version 2.12.7

Any idea how is that possible?

EDIT1

Is there a way to ensure that the version of the Worksheet is the same as the one set in the sbt project? Am i looking at the wrong values?

2

There are 2 best solutions below

0
MaatDeamon On BEST ANSWER

Official answer from JetBrains:

Is there a way to ensure that the version of the Worksheet is the same as the one set in the sbt project? Am I looking at the wrong values?

The actual version of scala used in the worksheet is 2.12.12 (or whatever version is used in module). You can verify that e.g. by using some 2.13.3-specific syntax in worksheet, e.g val x: 42 = 42.

Any idea how is that possible?

The reason util.Properties.versionString returned 2.12.7 is a bug in our classloaders (similar to SCL-9229). versionString search for library.propertis resource and reads the version string from there. Due to the bug, resources of scala library of Scala Plugins itself (2.12.7 in 2020.2) leaked to the REPL instance. The bug was identified, fix is in progress.

2
Tomer Shetah On

I am not sure where 2.12.7 comes from, but if you change the run type from REPL into plain, the worksheet will be entirely compiled, with the Scala version defined in your build.sbt.

Quoting from Intellij Scala worksheet Run type difference explain:

Plain evaluation model compiles the whole worksheet in one go before evaluating expressions, whilst REPL evaluation model evaluates each expression on the go before moving to the next one.

This is where you configure:

enter image description here

This is the result:

enter image description here