VirtusLab / scala-cli

Scala CLI is a command-line tool to interact with the Scala language. It lets you compile, run, test, and package your Scala code (and more!)
https://scala-cli.virtuslab.org
Apache License 2.0
550 stars 129 forks source link

Dashes in script file names make Scala Native complain during linking, with Scala 2 #1266

Open alexarchambault opened 2 years ago

alexarchambault commented 2 years ago

Not sure if it's a Scala CLI bug, or more of a Scala Native bug.

Version(s) 0.1.11

Describe the bug

Having a - in the name of an .sc file, such as test-native.sc, makes Scala Native complain that the main class is missing, when using Scala 2 (things seem to work fine with Scala 3).

To Reproduce

$ cat test-native.sc
println("Hello")

$ scala-cli --native test-native.sc 
Compiling project (Scala 3.1.3, Scala Native)
Compiled project (Scala 3.1.3, Scala Native)
[info] Linking (1544 ms)
[info] Discovered 664 classes and 3692 methods
[info] Optimizing (debug mode) (1658 ms)
[info] Generating intermediate code (1162 ms)
[info] Produced 8 files
[info] Compiling to native code (1976 ms)
[info] Linking native code (immix gc, none lto) (116 ms)
[info] Total (6554 ms)
Hello

$ scala-cli --native test-native.sc --scala 2.13
Compiling project (Scala 2.13.8, Scala Native)
Compiled project (Scala 2.13.8, Scala Native)
[error] Found 2 missing definitions while linking
[error] Not found Top(test$minusnative_sc)
[error] Not found Member(Top(test$minusnative_sc),D4mainLAL16java.lang.String_uEo)
Exception in thread "main" scala.scalanative.linker.LinkingException: Undefined definitions found in reachability phase
    at scala.scalanative.linker.Reach.fail(Reach.scala:976)
    at scala.scalanative.linker.Reach.reportMissing(Reach.scala:971)
    at scala.scalanative.linker.Reach.result(Reach.scala:47)
    at scala.scalanative.linker.Reach$.apply(Reach.scala:989)
    at scala.scalanative.linker.Link$.apply(Link.scala:13)
    at scala.scalanative.build.ScalaNative$.$anonfun$link$1(ScalaNative.scala:32)
    at scala.scalanative.build.Logger.time(Logger.scala:35)
    at scala.scalanative.build.Logger.time$(Logger.scala:32)
    at scala.scalanative.cli.utils.FilteredLogger.time(FilteredLogger.scala:5)
    at scala.scalanative.build.ScalaNative$.link(ScalaNative.scala:32)
    at scala.scalanative.build.Build$.$anonfun$build$1(Build.scala:65)
    at scala.scalanative.build.Logger.time(Logger.scala:35)
    at scala.scalanative.build.Logger.time$(Logger.scala:32)
    at scala.scalanative.cli.utils.FilteredLogger.time(FilteredLogger.scala:5)
    at scala.scalanative.build.Build$.build(Build.scala:55)
    at scala.scalanative.cli.ScalaNativeLd$.$anonfun$runLd$3(ScalaNativeLd.scala:71)
    at scala.scalanative.util.Scope$.apply(Scope.scala:32)
    at scala.scalanative.cli.ScalaNativeLd$.runLd(ScalaNativeLd.scala:70)
    at scala.scalanative.cli.ScalaNativeLd$.main(ScalaNativeLd.scala:44)
    at scala.scalanative.cli.ScalaNativeLd.main(ScalaNativeLd.scala)
Error: scala.build.errors.ScalaNativeBuildError: Error compiling with Scala Native
For more details, please see './.scala-build/stacktraces/1660915068-11415421066413436769.log'

$ scala-cli --native test-native.sc --scala 2.12
Compiling project (Scala 2.12.16, Scala Native)
Compiled project (Scala 2.12.16, Scala Native)
[error] Found 2 missing definitions while linking
[error] Not found Top(test$minusnative_sc)
[error] Not found Member(Top(test$minusnative_sc),D4mainLAL16java.lang.String_uEo)
Exception in thread "main" scala.scalanative.linker.LinkingException: Undefined definitions found in reachability phase
    at scala.scalanative.linker.Reach.fail(Reach.scala:976)
    at scala.scalanative.linker.Reach.reportMissing(Reach.scala:971)
    at scala.scalanative.linker.Reach.result(Reach.scala:47)
    at scala.scalanative.linker.Reach$.apply(Reach.scala:989)
    at scala.scalanative.linker.Link$.apply(Link.scala:13)
    at scala.scalanative.build.ScalaNative$.$anonfun$link$1(ScalaNative.scala:32)
    at scala.scalanative.build.Logger.time(Logger.scala:35)
    at scala.scalanative.build.Logger.time$(Logger.scala:32)
    at scala.scalanative.cli.utils.FilteredLogger.time(FilteredLogger.scala:5)
    at scala.scalanative.build.ScalaNative$.link(ScalaNative.scala:32)
    at scala.scalanative.build.Build$.$anonfun$build$1(Build.scala:65)
    at scala.scalanative.build.Logger.time(Logger.scala:35)
    at scala.scalanative.build.Logger.time$(Logger.scala:32)
    at scala.scalanative.cli.utils.FilteredLogger.time(FilteredLogger.scala:5)
    at scala.scalanative.build.Build$.build(Build.scala:55)
    at scala.scalanative.cli.ScalaNativeLd$.$anonfun$runLd$3(ScalaNativeLd.scala:71)
    at scala.scalanative.util.Scope$.apply(Scope.scala:32)
    at scala.scalanative.cli.ScalaNativeLd$.runLd(ScalaNativeLd.scala:70)
    at scala.scalanative.cli.ScalaNativeLd$.main(ScalaNativeLd.scala:44)
    at scala.scalanative.cli.ScalaNativeLd.main(ScalaNativeLd.scala)
Error: scala.build.errors.ScalaNativeBuildError: Error compiling with Scala Native
For more details, please see './.scala-build/stacktraces/1660915082-12928571838333692371.log'
WojciechMazur commented 2 years ago

The problem was happening on the SN side. This issue would be fixed in Scala Native 0.4.8 https://github.com/scala-native/scala-native/pull/2955