com-lihaoyi / Ammonite

Scala Scripting
http://ammonite.io
MIT License
2.6k stars 365 forks source link

REPL throws `@ error while loading CodeColors` for Scala 3 LTS #1504

Closed Gedochao closed 3 weeks ago

Gedochao commented 3 weeks ago

Affected versions

Ammonite 3.0.0-M2-9-88291dd8 + Scala 3 LTS (3.3.3)

Description

The newest nightly ammonite repl throws an error when launched with Scala 3 LTS.

scala-cli --amm --ammonite-ver 3.0.0-M2-9-88291dd8 -S lts --power
# Loading...
# Welcome to the Ammonite Repl 3.0.0-M2-9-88291dd8 (Scala 3.3.3 Java 17)
# @ error while loading CodeColors,
# class file ammonite/util/CodeColors.class is broken, reading aborted with class dotty.tools.tasty.UnpickleException
# TASTy signature has wrong version.
#  expected: {majorVersion: 28, minorVersion: 3}
#  found   : {majorVersion: 28, minorVersion: 4}
# 
# This TASTy file was produced by a more recent, forwards incompatible release.
# To read this TASTy file, please upgrade your tooling.
# The TASTy file was produced by Scala 3.4.2.

Context

This is seemingly caused by https://github.com/com-lihaoyi/Ammonite/pull/1503, the issue is not present in the earlier version.

lihaoyi commented 3 weeks ago

Seems like scalacli is pulling in the wrong version of ammonite, for scala 3.4.2 instead of 3.3.x

Gedochao commented 3 weeks ago

Seems like scalacli is pulling in the wrong version of ammonite, for scala 3.4.2 instead of 3.3.x

@lihaoyi Hmm... I'm not so sure if it is. I pinned the version used by LTS to 3.0.0-M2-8-ba4429a2 in https://github.com/VirtusLab/scala-cli/pull/2960, which fixed it... I can investigate, but I believe we're pulling it the same across versions. So shouldn't be any different.

Gedochao commented 3 weeks ago

https://github.com/VirtusLab/scala-cli/blob/2662fd56fd052e10e06047b97d3e8717a1ec4cce/modules/build/src/main/scala/scala/build/ReplArtifacts.scala#L55

Hmm... I'm pretty sure the triple colon gives me the _3.3.3 version.

image

And indeed, I seem to be getting the correct artifacts, as I debug. So I'm guessing something is wrong with the artifact. And yeah, downgrading to 3.0.0-M2-8-ba4429a2 when used with the LTS does fix it. 3.0.0-M2-9-88291dd8 does introduce 3.4.2 support (which is a first in the 3.4.x line), so that was worth bringing in, but I still believe something is wrong with the _3.3.3 artifact, unless I'm missing something.

tgodzik commented 3 weeks ago

Getting a bit different error in Metals via ammonite runner:

SEVERE: Internal error: java.util.concurrent.ExecutionException: Boxed Exception
java.util.concurrent.CompletionException: java.util.concurrent.ExecutionException: Boxed Exception
    at java.base/java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:332)
    at java.base/java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:347)
    at java.base/java.util.concurrent.CompletableFuture$UniAccept.tryFire(CompletableFuture.java:708)
    at java.base/java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:510)
    at java.base/java.util.concurrent.CompletableFuture.completeExceptionally(CompletableFuture.java:2162)
    at ammonite.interp.script.AmmoniteBuildServer$.on$$anonfun$1(AmmoniteBuildServer.scala:492)
    at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:484)
    at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.base/java.lang.Thread.run(Thread.java:840)
Caused by: java.util.concurrent.ExecutionException: Boxed Exception
    at scala.concurrent.impl.Promise$.scala$concurrent$impl$Promise$$resolve(Promise.scala:99)
    at scala.concurrent.impl.Promise$Transformation.handleFailure(Promise.scala:444)
    at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:506)
    ... 3 more
Caused by: java.lang.AssertionError: assertion failed: asTerm called on not-a-Term val <none>
    at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
    at dotty.tools.dotc.core.Symbols$Symbol.asTerm(Symbols.scala:169)
    at dotty.tools.dotc.ast.tpd$.New(tpd.scala:528)
    at dotty.tools.dotc.core.Annotations$Annotation$Child$.makeChildLater$1(Annotations.scala:231)
    at dotty.tools.dotc.core.Annotations$Annotation$Child$.later$$anonfun$1(Annotations.scala:234)
    at dotty.tools.dotc.core.Annotations$LazyAnnotation.tree(Annotations.scala:140)
    at d
2024.06.14 01:06:19 INFO  Ammonite: otty.tools.dotc.core.Annotations$Annotation$Child$.unapply(Annotations.scala:242)
    at dotty.tools.dotc.typer.Namer.insertInto$1(Namer.scala:477)
    at dotty.tools.dotc.typer.Namer.addChild(Namer.scala:488)
    at dotty.tools.dotc.typer.Namer$Completer.register$1(Namer.scala:911)
    at dotty.tools.dotc.typer.Namer$Completer.registerIfChild$$anonfun$1(Namer.scala:920)
    at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
    at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
    at scala.collection.immutable.List.foreach(List.scala:333)
    at dotty.tools.dotc.typer.Namer$Completer.registerIfChild(Namer.scala:920)
    at dotty.tools.dotc.typer.Namer$Completer.complete(Namer.scala:815)
    at dotty.tools.dotc.core.SymDenotations$SymDenotation.completeFrom(SymDenotations.scala:174)
    at dotty.tools.dotc.core.Denotations$Denotation.completeInfo$1(Denotations.scala:187)
    at dotty.tools.dotc.core.Denotations$Denotation.info(Denotations.scala:189)
    at dotty.tools.dotc.core.SymDenotations$SymDenotation.ensureCompleted(SymDenotations.scala:393)
    at dotty.tools.dotc.typer.Typer.retrieveSym(Typer.scala:2991)
    at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3016)
    at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3114)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3187)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3191)
    at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3213)
    at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3259)
    at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:2669)
    at dotty.tools.dotc.typer.Typer.typedTypeOrClassDef$1(Typer.scala:3038)
    at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:3042)
    at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3114)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3187)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3191)
    at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3213)
    at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3259)
    at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.sc
2024.06.14 01:06:19 INFO  Ammonite: ala:2812)
    at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3083)
    at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3115)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3187)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3191)
    at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:3240)
    at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:3259)
    at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:2812)
    at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:3083)
    at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:3115)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3187)
    at dotty.tools.dotc.typer.Typer.typed(Typer.scala:3191)
    at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:3303)
    at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$1(TyperPhase.scala:44)
    at dotty.tools.dotc.typer.TyperPhase.typeCheck$$anonfun$adapted$1(TyperPhase.scala:50)
    at scala.Function0.apply$mcV$sp(Function0.scala:42)
    at dotty.tools.dotc.core.Phases$Phase.monitor(Phases.scala:440)
    at dotty.tools.dotc.typer.TyperPhase.typeCheck(TyperPhase.scala:50)
    at dotty.tools.dotc.typer.TyperPhase.runOn$$anonfun$3(TyperPhase.scala:84)
    at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
    at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
    at scala.collection.immutable.List.foreach(List.scala:333)
    at dotty.tools.dotc.typer.TyperPhase.runOn(TyperPhase.scala:84)
    at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:246)
    at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
    at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
    at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
    at dotty.tools.dotc.Run.runPhases$1(Run.scala:262)
    at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:270)
    at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:279)
    at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:71)
    at dotty.tools.dotc.Run.compileUnits(Run.scala:279)
    at dotty.tools.dotc.Run.compileUnit
2024.06.14 01:06:19 INFO  Ammonite: s(Run.scala:200)
    at ammonite.compiler.Compiler.compile(Compiler.scala:233)
    at ammonite.interp.script.SingleScriptCompiler.compileBlock$$anonfun$2(SingleScriptCompiler.scala:222)
    at ammonite.util.Res$Success.map(Res.scala:63)
    at ammonite.interp.script.SingleScriptCompiler.compileBlock(SingleScriptCompiler.scala:239)
    at ammonite.interp.script.SingleScriptCompiler.$anonfun$20(SingleScriptCompiler.scala:249)
    at ammonite.util.Res$.fold$$anonfun$1(Res.scala:27)
    at scala.collection.LinearSeqOps.foldLeft(LinearSeq.scala:183)
    at scala.collection.LinearSeqOps.foldLeft$(LinearSeq.scala:179)
    at scala.collection.immutable.List.foldLeft(List.scala:79)
    at ammonite.util.Res$.fold(Res.scala:28)
    at ammonite.interp.script.SingleScriptCompiler.compileBlocks(SingleScriptCompiler.scala:253)
    at ammonite.interp.script.SingleScriptCompiler.apply(SingleScriptCompiler.scala:261)
    at ammonite.interp.script.ScriptCompiler.doCompile(ScriptCompiler.scala:236)
    at ammonite.interp.script.ScriptCompiler.compileIfNeeded$$anonfun$1(ScriptCompiler.scala:206)
    at scala.Option.getOrElse(Option.scala:201)
    at ammonite.interp.script.ScriptCompiler.compileIfNeeded(ScriptCompiler.scala:209)
    at ammonite.interp.script.ScriptCompiler.compile(ScriptCompiler.scala:82)
    at ammonite.interp.script.AmmoniteBuildServer.$anonfun$12(AmmoniteBuildServer.scala:379)
    at scala.Option.getOrElse(Option.scala:201)
    at ammonite.interp.script.AmmoniteBuildServer.compileScript(AmmoniteBuildServer.scala:388)
    at ammonite.interp.script.AmmoniteBuildServer.$anonfun$15(AmmoniteBuildServer.scala:400)
    at ammonite.interp.script.ScriptCompiler.$anonfun$1$$anonfun$5$$anonfun$1$$anonfun$2(ScriptCompiler.scala:62)
    at scala.util.Either.flatMap(Either.scala:352)
    at ammonite.interp.script.ScriptCompiler.$anonfun$1$$anonfun$5$$anonfun$1(ScriptCompiler.scala:66)
    at scala.util.Either.flatMap(Either.scala:352)
    at ammonite.interp.script.ScriptCompiler.$anonfun$1$$anonfun$5(ScriptCompiler.scala:66)
    at scala.util.Either.flatMap(Either.scala:352)
    at ammonite.interp.script.Script
2024.06.14 01:06:19 INFO  Ammonite: Compiler.$anonfun$1(ScriptCompiler.scala:66)
    at scala.util.Either.flatMap(Either.scala:352)
    at ammonite.interp.script.ScriptCompiler.compile(ScriptCompiler.scala:66)
    at ammonite.interp.script.AmmoniteBuildServer.compileScript(AmmoniteBuildServer.scala:400)
    at ammonite.interp.script.AmmoniteBuildServer.$anonfun$16$$anonfun$1(AmmoniteBuildServer.scala:410)
    at scala.collection.immutable.List.map(List.scala:246)
    at scala.collection.immutable.List.map(List.scala:79)
    at ammonite.interp.script.AmmoniteBuildServer.$anonfun$16(AmmoniteBuildServer.scala:410)
    at scala.collection.immutable.List.flatMap(List.scala:293)
    at ammonite.interp.script.AmmoniteBuildServer.buildTargetCompile$$anonfun$1(AmmoniteBuildServer.scala:410)
    at scala.concurrent.Future$.$anonfun$apply$1(Future.scala:687)
    at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:467)
    ... 3 more

2024.06.14 01:06:19 INFO  Cancelling compilation on Ammonite server
org.eclipse.lsp4j.jsonrpc.ResponseErrorException: Internal error.
    at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.handleResponse(RemoteEndpoint.java:220)
    at org.eclipse.lsp4j.jsonrpc.RemoteEndpoint.consume(RemoteEndpoint.java:204)
    at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.handleMessage(StreamMessageProducer.java:185)
    at org.eclipse.lsp4j.jsonrpc.json.StreamMessageProducer.listen(StreamMessageProducer.java:97)
    at org.eclipse.lsp4j.jsonrpc.json.ConcurrentMessageProcessor.run(ConcurrentMessageProcessor.java:114)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
    at java.util.concurrent.FutureTask.run(FutureTask.java:264)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
    at java.lang.Thread.run(Thread.java:840)

we haven't changed any versions at all here.

tgodzik commented 3 weeks ago

Also cs launch --scala 3.3.3 ammonite:3.0.0-M2-9-88291dd8 fails.

tgodzik commented 3 weeks ago

My guess is that somehow because of https://github.com/com-lihaoyi/Ammonite/blob/88291dd8321fc0b154bcf7ad0164fd3262e1326c/build.sc#L333 uses only bin versions a wrong binary version is selected and utils should be fully cross compiled

tgodzik commented 3 weeks ago

Yep, direct dependency on org.scala-lang:scala3-library_3:3.4.2

cs resolve -t --scala-version 3.3.3 ammonite:3.0.0-M2-9-88291dd8 | grep 3.4. -A 20 -B 10 :

   ├─ com.lihaoyi:ammonite-util_3:3.0.0-M2-9-88291dd8
   │  ├─ com.lihaoyi:fansi_3:0.5.0
   │  │  ├─ com.lihaoyi:sourcecode_3:0.4.0 -> 0.4.2
   │  │  │  └─ org.scala-lang:scala3-library_3:3.3.1 -> 3.3.3
   │  │  │     └─ org.scala-lang:scala-library:2.13.12 -> 2.13.14
   │  │  └─ org.scala-lang:scala3-library_3:3.3.1 -> 3.3.3
   │  │     └─ org.scala-lang:scala-library:2.13.12 -> 2.13.14
   │  ├─ com.lihaoyi:os-lib_3:0.10.2
   │  │  ├─ com.lihaoyi:geny_3:1.1.0
   │  │  │  └─ org.scala-lang:scala3-library_3:3.3.1 -> 3.3.3
   │  │  │     └─ org.scala-lang:scala-library:2.13.12 -> 2.13.14
   │  │  └─ org.scala-lang:scala3-library_3:3.3.1 -> 3.3.3
   │  │     └─ org.scala-lang:scala-library:2.13.12 -> 2.13.14
   │  ├─ com.lihaoyi:pprint_3:0.9.0
   │  │  ├─ com.lihaoyi:fansi_3:0.5.0
   │  │  │  ├─ com.lihaoyi:sourcecode_3:0.4.0 -> 0.4.2
   │  │  │  │  └─ org.scala-lang:scala3-library_3:3.3.1 -> 3.3.3
   │  │  │  │     └─ org.scala-lang:scala-library:2.13.12 -> 2.13.14
   │  │  │  └─ org.scala-lang:scala3-library_3:3.3.1 -> 3.3.3
   │  │  │     └─ org.scala-lang:scala-library:2.13.12 -> 2.13.14
   │  │  ├─ com.lihaoyi:sourcecode_3:0.4.0 -> 0.4.2
   │  │  │  └─ org.scala-lang:scala3-library_3:3.3.1 -> 3.3.3
   │  │  │     └─ org.scala-lang:scala-library:2.13.12 -> 2.13.14
   │  │  └─ org.scala-lang:scala3-library_3:3.3.1 -> 3.3.3
   │  │     └─ org.scala-lang:scala-library:2.13.12 -> 2.13.14
   │  ├─ org.scala-lang:scala3-library_3:3.4.2 -> 3.3.3 (possible incompatibility)
   │  │  └─ org.scala-lang:scala-library:2.13.12 -> 2.13.14
lihaoyi commented 3 weeks ago

This is very strange. When I build the pom locally via ./mill show "amm.util[3.3.3].pom", and compare it to what's online at https://search.maven.org/artifact/com.lihaoyi/ammonite-util_3/3.0.0-M2-9-88291dd8/jar, I get exactly the same file EXCEPT the scala3-library_3 version is different:

lihaoyi Ammonite$ ./mill show "amm.util[3.3.3].pom"

lihaoyi Ammonite$ curl 'https://search.maven.org/remotecontent?filepath=com/lihaoyi/ammonite-util_3/3.0.0-M2-9-88291dd8/ammonite-util_3-3.0.0-M2-9-88291dd8.pom' -o web.pom
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  2367  100  2367    0     0    484      0  0:00:04  0:00:04 --:--:--   577

lihaoyi Ammonite$ diff /Users/lihaoyi/Github/Ammonite/out/amm/util/3.3.3/pom.dest/ammonite-util_3-3.0.0-M2-9-88291dd8.pom web.pom
61c61
<             <version>3.3.3</version>
---
>             <version>3.4.2</version>

I don't know what on earth is going on here

lihaoyi commented 3 weeks ago

So the problem appears to be that amm.util[3.3.3].pom anf amm.util[3.4.2].pom have conflicting artifactScalaVersions, since they both resolve to _3, and those collide on upload.

lihaoyi commented 3 weeks ago

Fix https://github.com/com-lihaoyi/Ammonite/pull/1507