1

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?

Tomer Shetah
  • 8,413
  • 7
  • 27
  • 35
MaatDeamon
  • 9,532
  • 9
  • 60
  • 127

2 Answers2

2

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

Tomer Shetah
  • 8,413
  • 7
  • 27
  • 35
  • I never used the plain mode, not sure of the advantages for rapid prototyping. Maybe better using the worksheet as ammonite script in that case, less magic ... ??? Could explain essentially what is the exact difference ? The worksheet object is fully compile, the main contain whatever is in your worksheet ? It get execute with scalac? Where is the compiled file ? What’s working directory and all ? Sounds like a lot of magic :) – MaatDeamon Nov 15 '20 at 07:49
  • 1
    It does partially. I will give a chance for few more to see if someone come up with the explanation or 2.12.7 and if it can be changed. If not well will stick with yours and move on – MaatDeamon Nov 15 '20 at 11:31
1

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.

Tomer Shetah
  • 8,413
  • 7
  • 27
  • 35
MaatDeamon
  • 9,532
  • 9
  • 60
  • 127