Scala worksheet not working in Intellij - scala

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".

Related

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

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);

Can't expand macros compiled by previous versions of Scala

I changed my Scala version from 2.10.x to 2.11.8. I am getting some compilation issues. I tried, but still not able to resolve because I am poor in Scala and sbt.
WebService.scala:36: can't expand macros compiled by previous versions of Scala
[error] logger.error(s"WebService.getSiteData(${Id}): Unknown Error, Error Message: $e")
What might be the issue here?
I resolved this issue but it not a single thing, I did couple of things:
First I gone through the error location in WebService.scala.
Then to the corresponding "Logger" class.
I check from which jar that "Logger" class coming.
I found that it referring to some thing else jar than what I am expecting.
That jar is coming from one of my dependent project (modules) so in build.sbt, those dependent jars I excluded that wrong jar which I found.
After I changed the code in WebService.scala, I removed that import for logger and added new import having Logger what I expecting. I did same all the other places in my project.
WebService.scala:36: can't expand macros compiled by previous versions of Scala
[error] logger.error(s"WebService.getSiteData(${Id}): Unknown Error, Error Message: $e")
This is not particular to logger issue. If you are getting "can't expand macros compiled by previous versions of Scala" issue", you have to do same procedure for corresponding to your error (my case logger).
First time, I search online regarding this issue, I found same issue facing lot of people, but different library classes (I face Logger class issue).

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 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/

Scala errors in Eclipse 3.5 using Scala 2.8.0b, "Syntax error on token String"

I seem to be missing libraries but I am not certain.
In this file:
object Test {
def main(args: Array[String]) {
for (arg <- args)
println(arg)
}
}
I am not certain what leads to these errors:
Description Resource Path Location Type
Syntax error on token "object", interface expected TestSrc.scala /ScalaDataMiningFunctions/src line 1 Java Problem
Syntax error on token "String", delete this token TestSrc.scala /ScalaDataMiningFunctions/src line 2 Java Problem
Syntax error on token ":", delete this token TestSrc.scala /ScalaDataMiningFunctions/src line 2 Java Problem
Syntax error on token "<", ( expected TestSrc.scala /ScalaDataMiningFunctions/src line 3 Java Problem
I may just need to go through the steps and do this in Netbeans instead, but I would prefer to find out what is going on.
In my lift project, which was created by using maven, I don't have these errors, but there are many jar files there that I don't have in mine.
One jar file is scala-compiler-2.7.3.jar that is in the lift project but not in my scala project.
The only libraries in my scala project are Scala Library version 2.8.0r19106-... and JRE System Library [jre1.6.0_07]
Eclipse is seeing your Scala sources as Java and choking on them (the clue is the text "Java Problem" at the end of each problem report).
Most likely you don't have JDT Weaving enabled (or not enabled successfully), so please follow the troubleshooting instructions here,
http://scala-ide.assembla.com/wiki/show/scala-ide/Troubleshooting
and if you still have issues, please follow up on the scala-ide-user list,
http://groups.google.com/group/scala-ide-user
The scala plugin for Eclipse is still quite immature. If you are not locked into eclipse i would advise you to try out the netbeans plugin which is alot more stable. :)
please install scala plugin to eclipse
add following site
http://download.scala-ide.org/update-current-35
it will work...