scala3
scala3 copied to clipboard
Bad symbolic reference. A signature refers to JFunction1$mcZI$sp/T in package scala.runtime.java8 which is not available.
Compiler version
scala 3.1.3
If you're not sure what version you're using, run print scalaVersion from sbt
(if you're running scalac manually, use scalac -version instead).
Output
./bin/scala -deprecation
Welcome to Scala 3.1.3 (18.0.1, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
scala> val r=Iterator.from(20)
| .takeWhile(_<69)
val r: Iterator[Int] = <iterator>
scala> val r=Iterator.from(20)
| .takeWhile(_<69).foreach(println)
Bad symbolic reference. A signature
refers to JFunction1$mcZI$sp/T in package scala.runtime.java8 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.
1 error found
Sometimes, I run some example codes like the previous screenshot code. but in other times, it works fine.
Expectation
@topazus do you consistently get this error when you run it in a fresh REPL session? I can recall getting similar errors in REPL but that has never been something I managed to reproduce later.
@prolativ Yes, I got the error for plenty of times in the past few days.
But does this happen always for this snippet
val r=Iterator.from(20).takeWhile(_<69)
val r=Iterator.from(20).takeWhile(_<69).foreach(println)
or just often but not 100% deterministically? Or do you have more examples of code causing this problem? Could you try starting the REPL with scala-cli?
scala-cli repl -S 3.1.3 --jvm 18 -O -deprecation
Does the error occur also in this case?
But does this happen always for this snippet
val r=Iterator.from(20).takeWhile(_<69) val r=Iterator.from(20).takeWhile(_<69).foreach(println)or just often but not 100% deterministically?
the above screenshot occured the error.
Is this error caused by my operation of recreating immutable variable `val` with same name, or java environment variable?
Could you try starting the REPL with scala-cli?
scala-cli repl -S 3.1.3 --jvm 18 -O -deprecation
ok, I will try this.
./scala-cli repl -S 3.1.3 --jvm system -O -deprecation
use scala-cli, after evaluating several sample code, the same error still occured. @prolativ
detailed output, exactly copied from terminal, error in the very end
felix@Felixs-MacBook-Air ~ % ./scala-cli repl -S 3.1.3 --jvm system -O -deprecation
Welcome to Scala 3.1.3 (18.0.1, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
scala>
| val a=List(0,1)
| val r=a.zip(a.tail)
val a: List[Int] = List(0, 1)
val r: List[(Int, Int)] = List((0,1))
scala>
| val a1=List(0,1).zip(List(0,1).tail).map (n => n._1 + n._2 )
val a1: List[Int] = List(1)
scala> 1::List(1)
val res0: List[Int] = List(1, 1)
scala>
| val a1=0::1::List(0,1).zip(List(0,1).tail).map (n => n._1 + n._2 )
val a1: List[Int] = List(0, 1, 1)
scala>
| val a2=a1.zip(a1.tail).map (n => n._1 + n._2 )
val a2: List[Int] = List(1, 2)
scala>
|
| val a1=0::1::List(0,1).zip(List(0,1).tail).map (n => n._1 + n._2 )
| val a2=0::1::a1.zip(a1.tail).map (n => n._1 + n._2 )
| val a3=0::1::a2.zip(a2.tail).map (n => n._1 + n._2 )
val a1: List[Int] = List(0, 1, 1)
val a2: List[Int] = List(0, 1, 1, 2)
val a3: List[Int] = List(0, 1, 1, 2, 3)
scala>
| val fib: LazyList[Int] =
| BigInt(0) #:: BigInt(1) #:: fib.zip(fib.tail).map(n => n._1 + n._2)
|
-- [E007] Type Mismatch Error: -------------------------------------------------
3 | BigInt(0) #:: BigInt(1) #:: fib.zip(fib.tail).map(n => n._1 + n._2)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| Found: LazyList[Matchable]
| Required: LazyList[Int]
|
| longer explanation available when compiling with `-explain`
1 error found
scala>
| val fib: LazyList[BigInt] =
| BigInt(0) #:: BigInt(1) #:: fib.zip(fib.tail).map(n => n._1 + n._2)
|
val fib: LazyList[BigInt] = LazyList(<not computed>)
scala> fib.take(10).toList
val res1: List[BigInt] = List(0, 1, 1, 2, 3, 5, 8, 13, 21, 34)
scala>
| val ls:LazyList[Int]=0#:: ls.zipWithIndex((i,v)=>i+v+1)
-- [E081] Type Error: ----------------------------------------------------------
2 | val ls:LazyList[Int]=0#:: ls.zipWithIndex((i,v)=>i+v+1)
| ^
| Missing parameter type
|
| I could not infer the type of the parameter i.
-- [E081] Type Error: ----------------------------------------------------------
2 | val ls:LazyList[Int]=0#:: ls.zipWithIndex((i,v)=>i+v+1)
| ^
| Missing parameter type
|
| I could not infer the type of the parameter v.
2 errors found
scala>
| val ls:LazyList[Int]=0#:: ls.zipWithIndex((i,v)=>i+v+1)
-- [E081] Type Error: ----------------------------------------------------------
2 | val ls:LazyList[Int]=0#:: ls.zipWithIndex((i,v)=>i+v+1)
| ^
| Missing parameter type
|
| I could not infer the type of the parameter i.
-- [E081] Type Error: ----------------------------------------------------------
2 | val ls:LazyList[Int]=0#:: ls.zipWithIndex((i,v)=>i+v+1)
| ^
| Missing parameter type
|
| I could not infer the type of the parameter v.
2 errors found
scala>
| val ls: LazyList[Int] = 0 #:: ls.zipWithIndex(n => n._1 + n._2 + 1)
-- [E081] Type Error: ----------------------------------------------------------
2 | val ls: LazyList[Int] = 0 #:: ls.zipWithIndex(n => n._1 + n._2 + 1)
| ^
| Missing parameter type
|
| I could not infer the type of the parameter n.
1 error found
scala> lazy val ts: Stream[Int] =
| 0 #:: ts.zipWithIndex.map(p => p._1 + p._2 + 1)
|
1 warning found
-- Deprecation Warning: --------------------------------------------------------
1 |lazy val ts: Stream[Int] =
| ^^^^^^^^^^^
|class Stream in package scala.collection.immutable is deprecated since 2.13.0: Use LazyList (which is fully lazy) instead of Stream (which has a lazy tail only)
lazy val ts: Stream[Int]
scala>
scala>
| val ls: LazyList[Int] = 0 #:: ls.zipWithIndex.map(n => n._1 + n._2 + 1)
val ls: LazyList[Int] = LazyList(<not computed>)
scala> ls.take(10)
val res2: LazyList[Int] = LazyList(<not computed>)
scala> ls.take(10).toList
val res3: List[Int] = List(0, 1, 3, 6, 10, 15, 21, 28, 36, 45)
scala> lazy val ts: Stream[Int] =
| 0 #:: ts.zipWithIndex.map(p => p._1 + p._2 + 1)
|
1 warning found
-- Deprecation Warning: --------------------------------------------------------
1 |lazy val ts: Stream[Int] =
| ^^^^^^^^^^^
|class Stream in package scala.collection.immutable is deprecated since 2.13.0: Use LazyList (which is fully lazy) instead of Stream (which has a lazy tail only)
lazy val ts: Stream[Int]
scala> ts.take(10).toList
val res4: List[Int] = List(0, 1, 3, 6, 10, 15, 21, 28, 36, 45)
scala> List(9).zipWithIndex
val res5: List[(Int, Int)] = List((9,0))
scala>
| val a1=0::List(0).zipWithIndex.map(n => n._1 + n._2 + 1)
| val a2=0::a1.zipWithIndex.map(n => n._1 + n._2 + 1)
val a1: List[Int] = List(0, 1)
val a2: List[Int] = List(0, 1, 3)
scala> val a2=0::a1.zipWithIndex
val a2: List[Matchable] = List(0, (0,0), (1,1))
scala> a1.zipWithIndex.map
val res6: (((Int, Int)) => Any) => List[Any] = Lambda$1873/0x00000008011ba1f0@429904c9
scala> a1.zipWithIndex
val res7: List[(Int, Int)] = List((0,0), (1,1))
scala>
| val a1=0::List(0).zipWithIndex.map(n => n._1 + n._2 + 1)
| val a2=0::a1.zipWithIndex.map(n => n._1 + n._2 + 1)
| val a3=0::a2.zipWithIndex.map(n => n._1 + n._2 + 1)
val a1: List[Int] = List(0, 1)
val a2: List[Int] = List(0, 1, 3)
val a3: List[Int] = List(0, 1, 3, 6)
scala> a2.zipWithIndex
val res8: List[(Int, Int)] = List((0,0), (1,1), (3,2))
scala> val wordValue = {
| val ordinals = ('A' to 'Z').zipWithIndex.toMap
| (word:String) => word.length + word.map(ordinals).sum
| }
val wordValue: String => Int = Lambda$1897/0x00000008011c81f0@67a3713
scala> wordValue
val res9: String => Int = Lambda$1897/0x00000008011c81f0@67a3713
scala> val ls=Iterator.from(1).map(n=>(n+1)*n/2)
val ls: Iterator[Int] = <iterator>
scala> ls.take(10).toList
val res10: List[Int] = List(1, 3, 6, 10, 15, 21, 28, 36, 45, 55)
scala>
| val ls=Iterator.from(1).map(n=>(1 to n).sum)
Bad symbolic reference. A signature
refers to JFunction1$mcII$sp/T in package scala.runtime.java8 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.
1 error found
scala> val ls=Iterator.from(1).map(n=>(1 to n).sum)
Bad symbolic reference. A signature
refers to JFunction1$mcII$sp/T in package scala.runtime.java8 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.
1 error found
Digging deeper into that: does the problem occur if you don't use your globally installed Java version but rather force scala-cli to pull it for you or if you use an older version of JDK? E.g. if you use --jvm adopt:8 instead of --jvm system
Same issue:
scala Welcome to Scala 3.1.2-RC2 (18.0.2, Java OpenJDK 64-Bit Server VM).
I restarted the repl and previously erroring code worked. Strange that it happens at all, certainly baffling, particularly for newcomers.
I encountered the same error message when running the following code from the Scala 3 Book:
val nums = List(1,2,3)
nums.filter(_ > 1)
installation details: Ubuntu 22.04 on WSL (Windows 11), with Scala version 3.2.0 (installed with cs)
The odd thing is that after I followed the suggestion in this thread (running scala-cli repl -S 3.1.3 --jvm 18 -O -deprecation) the error vanished. What is stranger (at least to me...) is that after running that command, there were no errors even when running the default scala (without any parameters).
Please explain the root of the error, and why the "magical" command solved the issue
@godenji @topazus did you encounter this error while using WSL? Otherwise, what OS were you using?
And for people who were using WSL, did you install the JVM inside WSL or did you use the Windows version of the JVM?
did you encounter this error while using WSL? Otherwise, what OS were you using?
Linux (Fedora 35 at the time most likely).
FWIW, the error hasn't cropped up again in any REPL session since -- now on scala 3.2.2-RC1/Java 19.
Re-post as comment over here (Already mentioned in this thread).
Scala code runner version 3.2.1 -- Copyright 2002-2022, LAMP/EPFL
The following error appears randomly[1], so I am not sure you actually will be able to reproduce it.
Minimized code
scala> val arreglo: Array[Int] = Array(1, 2, 3, 4, 3, 2, 1)
scala> arreglo.sortWith(_ < _)
scala> val (sorted1: Array[Int], sorted2: Array[Int]) = arreglo.sortWith(_ < _).splitAt(arreglo.length / 2)
Output
Bad symbolic reference. A signature
refers to JFunction2$mcZII$sp/T in package scala.runtime.java8 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.
1 error found
Expectation
No error should be happening.
Underlying System Info.
The Scala REPL is running on top of Java 17 over a Windows Subsystem for Linux 2 (WSL2) installation.
Welcome to Scala 3.2.1 (17.0.5, Java Java HotSpot(TM) 64-Bit Server VM).
PRETTY_NAME="Ubuntu 22.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="22.04"
VERSION="22.04.1 LTS (Jammy Jellyfish)"
VERSION_CODENAME=jammy
ID=ubuntu
[1]

Thanks.
@godenji @topazus did you encounter this error while using WSL? Otherwise, what OS were you using?
I also encountered the error sometimes on Fedora 38.
-
error situation:

-
error-free situation:

After hitting this bug I am able to reproduce it with java 8, 11, 17 and 20 and with scala 3.0.0 and 3.3.0 (using scala-cli 1.0.1). All installed with sdkman. This is in Ubuntu 22.04.
It seem this bug is tied up to the REPL autocomplete somehow. To trigger it I evaluate the following expression:
List(1, 2).filter(_ % 2 == 0).foreach(println)
But don't simply copy paste and execute it. I can trigger the bug by autocompleting the foreach call in the expression. After 1-4 times autocompleting and executing I get the same result as the other reports. Typing fore and hitting tab is enough (for me).
FWIW, I can confirm that this works as a way to reproduce this bug on macOS as well:
But don't simply copy paste and execute it. I can trigger the bug by autocompleting the
foreachcall in the expression. After 1-4 times autocompleting and executing I get the same result as the other reports. Typingforeand hitting tab is enough (for me).
That's an excellent catch. Current plain REPL, completing as instructed:
➜ dotty git:(test/current) ./bin/scala
Welcome to Scala 3.3.2-RC1-bin-SNAPSHOT-git-9b70af9 (20.0.1, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
scala> List(1, 2).filter(_ % 2 == 0).foreach(println)
2
scala> List(1, 2).filter(_ % 2 == 0).foreach(println)
Bad symbolic reference. A signature
refers to JFunction1$mcZI$sp/T in package scala.runtime.java8 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.
1 error found
It's reproducible for me as well using the tab-completion trick. And in my experience it fails every time — I tried it about 10 times in a row just now, 100% failure rate. (MacOS, JDK 17, Scala 3.3.0 and 3.4.0-RC1-bin-20230810-c90ad6b-NIGHTLY) Doesn't matter whether I launch with scala-cli or with the bundled scala script.
A good next step an interested volunteer could take would be to try to turn it into a failing test case.
OK, I finally managed to reproduce the issue myself too. To me it looks like the problem is somehow connected with the fact that the class loader used by the REPL is evaluated lazily, after the REPL gets its input for the first time. E.g. evaluating
scala> println()
before trying the completion based reproduction from above makes the problem not occur.
A small rectification:
It seems it's not about what you evaluate before but whether there is only one completion suggestion or more.
So there will be no error after completing on List(1, 2).filter(_ % 2 == 0).for and choosing .foreach by pressing TAB. But for List(1, 2).filter(_ % 2 == 0).fore there is only one choice, which will make the error start appearing
Hello, I just got this same error in the Scala REPL with the example code from the Tour of Scala:
val salaries = Seq(20_000, 70_000, 40_000)
val newSalaries = salaries.map(_ * 2)
I'm on Windows 11.
C:\Users\###>cs java --installed
adopt:1.8.0-292 installed at C:\Users\olega\AppData\Local\Coursier\cache\arc\https\github.com\AdoptOpenJDK\openjdk8-binaries\releases\download\jdk8u292-b10\OpenJDK8U-jdk_x64_windows_hotspot_8u292b10.zip\jdk8u292-b10
C:\Users\###>java -version
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (AdoptOpenJDK)(build 1.8.0_292-b10)
OpenJDK 64-Bit Server VM (AdoptOpenJDK)(build 25.292-b10, mixed mode)
C:\Users\###>scala --version
Scala code runner version 3.3.0 -- Copyright 2002-2023, LAMP/EPFL
I tried opening a fresh scala REPL and typed in the same commands, and the error didn't occur. Weird.
Since the issue is visible on REPL, this is significantly impacting the developer experience. Can you please prioritize this?
I can't reproduce this any what way...
I tried it about 10 times in a row just now, 100% failure rate.
@SethTisue Can you provide more detailed reproducible steps?
@dwijnand try 3.3.x — I am still able to reproduce this every time on 3.3.2, but I'm not able to make it happen at all on 3.4.0
This is using Alfonso's repro steps: https://github.com/lampepfl/dotty/issues/15562#issuecomment-1595869505
Note that the error doesn't occur after you hit tab — it happens after you complete all the steps fully, twice: type (or paste) up to fore, hit tab (completing foreach), type (println), press enter
I tried (several times) with:
scala-cli repl -S "3.1.3" --jvm 17 -deprecation
scala-cli repl -S "3.2.0" --jvm 17 -deprecation
scala-cli repl -S "3.1.3" --jvm 18 -deprecation
scala-cli repl -S "3.2.0" --jvm 18 -deprecation
scala-cli repl -S "3.nightly" --jvm 21 -deprecation
and haven't been able to reproduce yet. I am on a MacBook Intel.
➜ ~/empty scala-cli repl -S "3.nightly" --jvm 21 -deprecation
Welcome to Scala 3.4.2-RC1-bin-20240219-9a79c14-NIGHTLY-git-9a79c14 (21.0.2, Java Java HotSpot(TM) 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
scala> val r=Iterator.from(20)
| .takeWhile(_<69)
val r: Iterator[Int] = <iterator>
scala> val r=Iterator.from(20)
| .takeWhile(_<69).foreach(println)
20
21
22
...
@dwijnand try 3.3.x
I was able to reproduce on the release-3.3.2 branch (7c9a142ee9) with bin/scala
I could replicate a few times by doing these steps as suggested above:
scala --jvm 18 -S 3.3.1 -deprecation
Welcome to Scala 3.3.1 (18.0.2, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
scala> List(1, 2).filter(_ % 2 == 0).foreach(println)
2
scala> List(1, 2).filter(_ % 2 == 0).foreach(println)
Bad symbolic reference. A signature
refers to JFunction1$mcZI$sp/T in package scala.runtime.java8 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.
1 error found
scala>
make sure to paste List(1, 2).filter(_ % 2 == 0).fore in the terminal, then autocomplete the foreach, then fill in (println) manually before <enter>
its nondeterministic how many times to enter these steps in a single repl session
(as I was also just saying on another ticket) it's not clear whether it's worth the effort to try to pinpoint which PR is responsible, or whether we should just wait until the next big wave of backports lands, and then test 3.3.x again to see if the problem went away. most fixes are being backported so that's grounds for optimism
I can reproduce the issue with 3.3.1 (LTS), but not 3.4 inside a docker container
docker pull openjdk
docker run -i -t openjdk /bin/bash
curl -fL https://github.com/coursier/coursier/releases/latest/download/cs-x86_64-pc-linux.gz | gzip -d > cs && chmod +x cs && ./cs setup
cd ~/.local/share/coursier/bin/
With scala-3.4
bash-4.4# scala
Welcome to Scala 3.4.0 (18.0.2.1, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
scala> List(1, 2).filter(_ % 2 == 0).foreach(println)
2
scala> List(1, 2).filter(_ % 2 == 0).foreach(println)
2
scala>
With scala-3.3.1
bash-4.4# ./cs install scala:3.3.1 && ./cs install scalac:3.3.1
bash-4.4# ./scala
Welcome to Scala 3.3.1 (18.0.2.1, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
scala> List(1, 2).filter(_ % 2 == 0).foreach(println)
2
scala> List(1, 2).filter(_ % 2 == 0).foreach(println)
Bad symbolic reference. A signature
refers to JFunction1$mcZI$sp/T in package scala.runtime.java8 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.
1 error found
I could replicate a few times by doing these steps as suggested above:
If it helps, this fails for me with Scala 3.3.1 and Java 11 on macOS 14.3 when I follow what @bishabosha wrote about pasting the code in:
Welcome to Scala 3.3.1 (11.0.11, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
scala> List(1, 2).filter(_ % 2 == 0).foreach(println)
2
scala> List(1, 2).filter(_ % 2 == 0).foreach(println)
Bad symbolic reference. A signature
refers to JFunction1$mcZI$sp/T in package scala.runtime.java8 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.
1 error found
So this doesn't crash in 3.4.x+ because of #19113.
The sequence of events is this:
-
Run line 1
List(1, 2).filter(_ % 2 == 0).foreach(println)runs in Run 2 (not sure where run 1 goes). You don't need to trigger the tab completion on the first line to trigger the bug. That runs through and succeeds. In doing so it runs the Erasure tree transformation which runs in erasure.next phase, and in that the "JFunction1$mcZI$sp" symbol and sym denotation are created (erasure.next = ElimErasedValueType == phaseID 40). -
Tab complete line 2
List(1, 2).filter(_ % 2 == 0).fore<tab>runs in Run 3. Now tab completion is run under-Ystop-after:typer, which means there are only 3 phases: parser, repl, typer. Because the code is incomplete it throws a type error ("value fore is not a member of List[Int] - did you mean List[Int].fold?") which is hidden as it should be. But that error message, also has the import suggestions addendum. The import suggestion addendum then traverse a bunch of things, including scala.runtime.java8 and encounters theJFunction1$mcZI$spand asks it a question (is it a package), which causes it to want to recompute its denotation. But, in the logic of bringForward (which toNewRun uses) the denotation's first phase (40) isn't <= the current run's last phase, but at the same time the symbol does exist, so it ultimately updates its last denotation as NoDenotation - this irreparably breaks the symbol it seems. -
Run line 2
List(1, 2).filter(_ % 2 == 0).foreach(println), runs in Run 4. Now we re-lookupJFunction1$mcZI$sp. Now the lookup (throughrequiredClass(specializedFunctionalInterface)) actually finds the ScopeEntry for the symbol created in run 2 (denotsNamed), but its denotation has be stored as NoDenotation, and doesn't update back to the right one, so the symbol is temporarily stubbed out as a StubSymbol but ultimately fails.
Asides from backporting #19113, so that we avoid forcing the tab completion message, which forces the import suggestions, which forces the erasure symbol to lose its lastDenot (i.e. the "avoid touching it so it doesn't break" approach) I'm not sure what the proper fix in or around Symbol#computeDenot and SingleDenotation#current should be...