scala-cli icon indicating copy to clipboard operation
scala-cli copied to clipboard

Adding Scalameta dependencies crashes `repl --amm`

Open Gedochao opened this issue 3 years ago • 5 comments

Version(s) 0.1.15-62-gab05d824-SNAPSHOT (https://github.com/VirtusLab/scala-cli/commit/ab05d824d9f19f22e4528ed4f69b68992338e424)

Describe the bug Passing dependencies to the Ammonite repl crashes it. EDIT: This seems to only happen with Scalameta dependencies.

To Reproduce

▶ cat deps.scala           
//> using lib "com.lihaoyi::os-lib:0.8.1"
▶ scala-cli repl --amm deps.scala
Compiling project (Scala 3.1.3, JVM)
Compiled project (Scala 3.1.3, JVM)
Loading...
Welcome to the Ammonite Repl 2.5.5 (Scala 3.1.3 Java 17.0.2)
@ os.pwd 
java.lang.NoSuchMethodError: 'void geny.Writable.$init$(geny.Writable)'
  upickle.Api$$anon$1.<init>(Api.scala:94)
  upickle.Api.stream(Api.scala:94)
  upickle.Api.stream$(Api.scala:92)
  upickle.default$.stream(Api.scala:157)
  ammonite.runtime.Storage$Folder$$anon$33.update(Storage.scala:220)
  ammonite.runtime.Storage$Folder$$anon$33.update(Storage.scala:208)
  ammonite.repl.Repl.$anonfun$action$6(Repl.scala:195)
  ammonite.repl.Repl.$anonfun$action$6$adapted(Repl.scala:194)
  ammonite.repl.AmmoniteFrontEnd.action(AmmoniteFrontEnd.scala:31)
  ammonite.repl.Repl.$anonfun$action$4(Repl.scala:194)
  ammonite.repl.Scoped.$anonfun$flatMap$1(Signaller.scala:45)
  ammonite.repl.Signaller.apply(Signaller.scala:28)
  ammonite.repl.Scoped.flatMap(Signaller.scala:45)
  ammonite.repl.Scoped.flatMap$(Signaller.scala:45)
  ammonite.repl.Signaller.flatMap(Signaller.scala:16)
  ammonite.repl.Repl.$anonfun$action$2(Repl.scala:178)
  ammonite.util.Catching.flatMap(Res.scala:115)
  ammonite.repl.Repl.action(Repl.scala:170)
  ammonite.repl.Repl.loop$1(Repl.scala:212)
  ammonite.repl.Repl.run(Repl.scala:227)
  ammonite.Main.$anonfun$run$1(Main.scala:236)
  scala.Option.getOrElse(Option.scala:201)
  ammonite.Main.run(Main.scala:224)
  ammonite.MainRunner.$anonfun$runRepl$1(MainRunner.scala:72)
  ammonite.MainRunner.watchLoop(MainRunner.scala:53)
  ammonite.MainRunner.runRepl(MainRunner.scala:72)
  ammonite.AmmoniteMain$.main0(AmmoniteMain.scala:99)
  ammonite.AmmoniteMain$.main(AmmoniteMain.scala:38)
  ammonite.Main$.main(Main.scala:273)
  ammonite.Main.main(Main.scala)

passing the dependency with --dependency gives the same behaviour:

▶ scala-cli repl --amm --dependency com.lihaoyi::os-lib:0.8.1
Loading...
Welcome to the Ammonite Repl 2.5.5 (Scala 3.1.3 Java 17.0.2)
@ os.pwd 
java.lang.NoSuchMethodError: 'void geny.Writable.$init$(geny.Writable)'
  upickle.Api$$anon$1.<init>(Api.scala:94)
  upickle.Api.stream(Api.scala:94)
  upickle.Api.stream$(Api.scala:92)
  upickle.default$.stream(Api.scala:157)
  ammonite.runtime.Storage$Folder$$anon$33.update(Storage.scala:220)
  ammonite.runtime.Storage$Folder$$anon$33.update(Storage.scala:208)
  ammonite.repl.Repl.$anonfun$action$6(Repl.scala:195)
  ammonite.repl.Repl.$anonfun$action$6$adapted(Repl.scala:194)
  ammonite.repl.AmmoniteFrontEnd.action(AmmoniteFrontEnd.scala:31)
  ammonite.repl.Repl.$anonfun$action$4(Repl.scala:194)
  ammonite.repl.Scoped.$anonfun$flatMap$1(Signaller.scala:45)
  ammonite.repl.Signaller.apply(Signaller.scala:28)
  ammonite.repl.Scoped.flatMap(Signaller.scala:45)
  ammonite.repl.Scoped.flatMap$(Signaller.scala:45)
  ammonite.repl.Signaller.flatMap(Signaller.scala:16)
  ammonite.repl.Repl.$anonfun$action$2(Repl.scala:178)
  ammonite.util.Catching.flatMap(Res.scala:115)
  ammonite.repl.Repl.action(Repl.scala:170)
  ammonite.repl.Repl.loop$1(Repl.scala:212)
  ammonite.repl.Repl.run(Repl.scala:227)
  ammonite.Main.$anonfun$run$1(Main.scala:236)
  scala.Option.getOrElse(Option.scala:201)
  ammonite.Main.run(Main.scala:224)
  ammonite.MainRunner.$anonfun$runRepl$1(MainRunner.scala:72)
  ammonite.MainRunner.watchLoop(MainRunner.scala:53)
  ammonite.MainRunner.runRepl(MainRunner.scala:72)
  ammonite.AmmoniteMain$.main0(AmmoniteMain.scala:99)
  ammonite.AmmoniteMain$.main(AmmoniteMain.scala:38)
  ammonite.Main$.main(Main.scala:273)
  ammonite.Main.main(Main.scala)


@  

Expected behaviour Ammonite repl should allow to add dependencies from the command line or with using directives.

Known workaround Just use the standard repl, it works fine:

▶ scala-cli repl --dependency com.lihaoyi::os-lib:0.8.1
Welcome to Scala 3.2.0 (17.0.2, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
                                                                                                                                                             
scala> os.pwd
val res0: os.Path = ~/IdeaProjects/scala-cli-tests/amm-repl

Also with using directives:

▶ cat deps.scala           
//> using lib "com.lihaoyi::os-lib:0.8.1"
▶ scala-cli repl deps.scala
Welcome to Scala 3.2.0 (17.0.2, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
                                                                                                                                                             
scala> os.pwd
val res0: os.Path = ~/IdeaProjects/scala-cli-tests/amm-repl

Extra context This was mentioned in a relevant discussion recently. https://github.com/VirtusLab/scala-cli/discussions/1420

test-jars are quite troublesome to work with in Ammonite. relevant ticket: https://github.com/com-lihaoyi/Ammonite/issues/1296

Gedochao avatar Oct 13 '22 12:10 Gedochao

cc @alexarchambault

Gedochao avatar Oct 13 '22 12:10 Gedochao

Och, I think it's related to an issue that we had with Scalameta and ammonite. Ammonite probably brings in geny version that is not binary compatible with the one used in Ammonite. Does this break with any other dependencies?

The solution to that would be to have Ammonite separate or shade the library it's using.

tgodzik avatar Oct 13 '22 12:10 tgodzik

But anyway this seems like an issue that can only be fixed within ammonite.

tgodzik avatar Oct 13 '22 12:10 tgodzik

Oh, huh. fair point. It seems to only break with Scalameta dependencies. It works when I tested it with cats-core and play-json. I'll adjust the ticket title.

Gedochao avatar Oct 13 '22 13:10 Gedochao

Alternatively we could shadow all the clalameta dependencies :thinking: , but probably would be better to do that also in ammonite

tgodzik avatar Oct 13 '22 14:10 tgodzik