Scala 3 IntelliJ error: ';' expected but ':' found - scala

I have a scala worksheet with the following code:
case class Square(width: Double):
val area = width * width
val window = Square(2)
window.area
I am trying to code in IntelliJ Idea, but I am getting the following error:
';' expected but ':' found. case class Square(width: Double):
The code is written in Scala 3, and the IntelliSense is set up correctly and reports no error, but I have a suspicion that the compiler is using some older version of the language. Is this a compiler setup issue and how do I fix it?
Edit: I am following a Scala learning course and downloading my project from there:
https://www.coursera.org/learn/effective-scala/supplement/UShnH/scala-3-repl-and-worksheets

The file was part of the project from the course I mentioned in the question. There was a file build.properties containing a single line:
sbt.version=1.5.3
After changing the version to
sbt.version=1.7.1
and relaunching Idea, the worksheet was evaluated correctly with no errors. The project was also set up to use version Java 18, which is used by sbt 1.7.1, but sbt 1.5.3 uses Java 11 instead, which might have been the issue.

case class Square(width; Double);

Related

jOOQ as a dependency in Scala 3 is broken?

I am trying to use jOOQ as dependency in a Scala 3 codebase:
libraryDependencies ++= Seq("org.jooq" % "jooq" % "3.16.6")
However when I try to do an import from this library -- like import org.jooq.DSLContext -- I get a compilation error.
The easiest way to reproduce this is using ammonite:
cs launch ammonite --scala 3.1.3
Loading...
Welcome to the Ammonite Repl 2.5.4-11-4f5bf2aa (Scala 3.1.3 Java 11.0.15)
# import $ivy.`org.jooq:jooq:3.16.6`, org.jooq.DSLContext
Bad symbolic reference. A signature
refers to ApiStatus/T in package org.jetbrains.annotations which is not available.
It may be completely missing from the current classpath, or the version on
the classpath might be incompatible with the version used when compiling the signature.
Caught: java.lang.AssertionError: assertion failed: failure to resolve inner class:
externalName = org.jetbrains.annotations.ApiStatus$Experimental,
outerName = org.jetbrains.annotations.ApiStatus,
innerName = Experimental
owner.fullName = org.jetbrains.annotations.ApiStatus
while parsing /Users/horta/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/jooq/jooq/3.16.6/jooq-3.16.6.jar(org/jooq/Named.class) while parsing annotations in /Users/horta/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/jooq/jooq/3.16.6/jooq-3.16.6.jar(org/jooq/Named.class)
Caught: java.lang.RuntimeException: bad constant pool index: 0 at pos: 740 while parsing annotations in /Users/horta/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/jooq/jooq/3.16.6/jooq-3.16.6.jar(org/jooq/Named.class)
...
This is not the complete error, it gives the same type of error on a bunch of different classes, always related with this annotation org.jetbrains.annotations.ApiStatus.Experimental.
I've reproduced this using Java 11 and 18 (openjdk), using SBT and ammonite, with all versions of Scala 3.
When using Scala 2.13.* everything works correctly, we're using that in production.
Any idea what might be going on here? Any potential clues or possible workarounds?
This is fixed in Scala 3 from version 3.2.0-RC1.
See reddit post in r/scala.

flink FoldingStateDescriptor is deprecated message

I am using Flink 1.8.0,
Trying to compile this line of code
val mockState = mock[KeyedStateStore]
with Intellij yields the following error (although that in sbt it seems to compile fine)
Error:(38, 23) class FoldingStateDescriptor in package state is
deprecated: see corresponding Javadoc for more information.
val mockState = mock[KeyedStateStore]
Although I am not calling the getFoldingState which is deprecated . any ideas how to get around that ?

error: ';' expected but double literal found

I am learning Scala and I am using typesafe activator to run the programs. I have my first program in the below path <downloads>\typesafe-activator-1.3.7\activator-dist-1.3.7\simple scala project\scala-2.11\Simple_scala_project.scala
Below is the program content
object Simple_scala_project {
def main (args:String): Unit =
{ println("My first scala program") }
}
when I am running the below command in the command line I am getting the error
scala -cp <downloads>\typesafe-activator-1.3.7\activator-dist-1.3.7\simple scala project\scala-2.11 Simple_scala_project
:1: error: ';' expected but double literal found.
Please help me in this.
I noted a similar error when I inadvertently placed a line including "sbt.version=1.3.13" (in my case) in the wrong file. I realize now that it should have gone into a folder insider my overall project folder called "project", inside a file called "build.properties" (instead of in "build.sbt").
The take-away from this is that I don't think you experienced a compiler error at all, but an error owing to some files in the project setup. Better SBT documentation may be found here.
It's absolutely true that SBT isn't needed for very simple examples, and indeed offends the sensibilities of ones volunteering to learn a new language (soon to be improved, Scala 3.x, not a hundred other extraneous technologies. I find IntelliJ Idea Community to be a boost, here, since its Scala support is first-rate, and will create simple example projects for you in a variety of ways Installing Scala / Installing Scala plugin for Idea.

Scala worksheet not working in Intellij

I have Intellij-IDEA 13.1.2. [edited, previously 13.0.2]
I use the scala-plugin.
I'm trying to use worksheets to evaluate code.
But all I got are two errors :
bad macro impl binding: versionFormat is supposed to be there
Unable to read an event from: rO0ABXNyADVvcmcuamV0YnJhaW5zLmpwcy5pbmNyZW1lbnRhbC...
I can run the scala console normally and execute my code in it,
but the worksheet doesn't function.
If my code is incorrect, it outputs an error indicating the interpreter failed to parse my code. I got the "bad macro impl binding" error only if my code is correct.
I tried creating a new project, but it didn't work.
I followed tutorial to configure scala in intellij but it didn't help either.
Is there an important configuration step I may have missed ? What does that error mean ?
EDIT : I tried the simplest thing in my worksheet like 1 or var x = 1 or println("Hello World!")
EDIT2: I'm not sure what I changed but now I have another error :
Error:error while loading MacroPrinter, class file needed by MacroPrinter is missing.
reference value macros of package reflect refers to nonexisting symbol.
UPDATE: Now it works fine under Intellij 13.1.5, Scala plugin 0.41.2 with both scala-2.10 and 2.11
I had the "Unable to read an event from" issue and switching from Scala 2.11.0 to Scala 2.10.4 fixed it for me.
I've shared a workaround in a similar question and I think it can work for this question as well:
I'm having the same issue with latest Idea and Scala plugin.
It seems that the worksheet has a problem executing any line which evaluates to Unit. Assigning is Unit, that's why your tableTest(0) = "zero" fails.
I've temporarily solved it with the following workaround:
this line will fail with error Error:Unable to read an event from:...
println("Will fail")
You can fix it by defining this helper method and using it for any Unit expression:
def unit(f: => Unit): String = {f; ""}
unit(println("Will work"))
You just have to ignore the line it generates in the output panel with res0: String =
You also can put this method in some object and import in any WS you need.
I am using IntelliJIDEA 13.1.2 and Scala Plugin 0.36.431. I tried to create a Scala Non-SBT project and created a worksheet file, then I met the "bad macro impl binding" problem. But if I created a Scala SBT project with a worksheet file, it worked well.
After updating to IntelliJ 13.1.5 build 135.1289 with JRE 1.7.0_60 and Scala 2.11.0 I had the same issue.
I fixed the problem by disabling the checkbox in settings -> IDE Settings -> Scala -> "Run compile server".

Scala error defining object

I've been trying to get a Scala hello world example running on Eclipse using the Scala plugin. Writing the following:
package scala_test
object Test {
def main(args: Array[String]) {
println("Hello, World")
}
}
produces the following error:
<console>:1: error: eof expected but '}' found.
}
^
I've tried this on both a Windows machine and a Mac (both were using Eclipse 3.7). I've tried commenting out the function definition (just leaving an empty body for the Test object) and the error still occurs. Any ideas as to what might cause this?
You need to see output in console, not in scala interpreter.
Just right click on scala file and select "run as scala application".
Make sure you have added the Scala nature to the project. On some versions of the plugin, that option is only available from the contextual "Configuration" menu if the Scala perspective is active. Your project icon should have an "S" instead of a "J" in the corner if you have made this change.
Make sure its in the right package, runs for me. I'm using this plugin
http://scala-ide.org/