Closed som-snytt closed 2 weeks ago
This is a continuation of the discussion from https://github.com/scala/scala3/issues/20110
If you use compiler-based highlighting, you can see in the editor that a wrong range is reported:
In the end, even though plain scalac
doesn't crash itself, it's still the one to blame as it seems.
It returns strange problem range, which includes redundant characters in the end.
The compiler doesn't crash by default because it doesn't use the range when reporting the error, but other tools do.
To check it with plain scalac
I implemented a simple custom reporter:
import scala.reflect.internal.util.{CodeAction, Position}
import scala.tools.nsc.Settings
import scala.tools.nsc.reporters.FilteringReporter
class MyReporter(_settings: Settings) extends FilteringReporter {
override def settings: Settings = _settings
override def doReport(pos: Position, msg: String, severity: Severity, actions: List[CodeAction]): Unit =
System.out.println(s"### [$severity] position: (${pos.start},${pos.end}), msg: $msg")
}
And then passed it to scalac
:
cat src/main/scala/Main.scala
class Main {
s"""aaa \s bbb"""
}%
cat src/main/scala/Main.scala | wc -m
34
scalac -Xreporter MyReporter -d . src/main/scala/Main.scala
### [ERROR] position: (23,36), msg: invalid escape '\s' not one of [\b, \t, \n, \f, \r, \\, \", \', \uxxxx] at index 4 in "aaa \s bbb". Use \\ for literal \.
Notice that file length is 34 but the range end offset is 36
, which leads to IndexOutOfBoundsException
in other tools, because none of them expect wrong ranges.
In order for my reporter to be detected by the compiler I had to patch JAVA_OPTS
and add the class path with the reporter (untitled68/target/scala-2.13/classes
) to -Xbootclasspatha/
.
I tried to use scala options like -bootclasspath
/-classpath
/-javabootclasspath
but it didn't work for some reason.
echo $JAVA_OPTS
-Xbootclasspath/a:/Users/dmitrii.naumenko/Desktop/dev/debug/untitled68/target/scala-2.13/classes:/Users/dmitrii.naumenko/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-reflect/2.13.13/scala-reflect-2.13.13.jar:/Users/dmitrii.naumenko/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-library/2.13.13/scala-library-2.13.13.jar:/Users/dmitrii.naumenko/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/org/scala-lang/scala-compiler/2.13.13/scala-compiler-2.13.13.jar
I noticed the Scala 3 ticket and thought this issue had been resolved. I'll assess the PR; I'm not sure if I closed it just for admin purposes (to clear the queue for 2.13.15).
Questions are not bug reports
"What the -- ??"
Reproduction steps
Scala version: 2.13.13
Problem
Correctly errors with
but crashes under Bloop.
Observed at https://github.com/scala/scala3/issues/20110