Scala Worksheet Extension Methods error: not found value extension - scala

I'm working on a Scala Worksheet file using this Visual Studio Code extension.
Everything works fine until I had to implement the Extension Method, the editor raises the error "not found: value extension" highlighting as shown in the image:
Following my scala version:
scala> util.Properties.versionNumberString
res0: String = 2.11.12
how can i bypass this problem?

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

Play Scala Slick: error withTableQuery: macro implementation not found: apply

I have an old Play 2.6 Scala project that works in production. I'm trying to start it back locally but now I have the following error with Slick: macro implementation not found: apply for every TableQuery
For instance with this line:
val usersCars: TableQuery[UsersCars] = TableQuery[UsersCars]
throws the error.
I tried to change the file where it is defined but without success.
The Scala version is 2.12.5

error: not found: value sc

I am new to Scala and am trying to code read a file using the following code
scala> val textFile = sc.textFile("README.md")
scala> textFile.count()
But I keep getting the following error
error: not found: value sc
I have tried everything, but nothing seems to work. I am using Scala version 2.10.4 and Spark 1.1.0 (I have even tried Spark 1.2.0 but it doesn't work either). I have sbt installed and compiled yet not able to run sbt/sbt assembly. Is the error because of this?
You should run this code using ./spark-shell. It's scala repl with provided sparkContext. You can find it in your apache spark distribution in folder spark-1.4.1/bin.

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/