Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scala-cli compile -d always clears the directory #1484

Closed
bishabosha opened this issue Oct 21, 2022 · 1 comment · Fixed by #1660
Closed

scala-cli compile -d always clears the directory #1484

bishabosha opened this issue Oct 21, 2022 · 1 comment · Fixed by #1660
Assignees
Labels
bug Something isn't working good first issue Good for newcomers scalac compatibility Issues tied with compatibility with the scalac (compiler) command. SIP-46 All the issues related to SIP-46 to turn Scala CLI into the official scala runner command. Warsaw Scala Spree

Comments

@bishabosha
Copy link
Contributor

bishabosha commented Oct 21, 2022

Version(s)
0.1.16

Describe the bug
for backwards compatibility, using the -d flag should not clear the directory before adding classes.

Instead, each compilation to the directory clears it, this makes it impossible to incrementally add classes to a directory.

To Reproduce

In this example, we simulate three compilation runs of "artefacts" that output to the same directory, the idea is that at runtime the lib classes should still exist, but they do not in this case:

// lib.scala
object lib:
  def foo = 23
// utils.scala
object utils:
  def bar = lib.foo
// app.scala
@main def app = println(utils.bar)
> mkdir out
> scala compile -d out lib.scala
> scala compile -d out -cp out utils.scala
> scala -cp out app.scala
Compiling project (Scala 3.2.0, JVM)
Compiled project (Scala 3.2.0, JVM)
Exception in thread "main" java.lang.NoClassDefFoundError: lib$
	at utils$.bar(Macros.scala:5)
	at App$package$.app(App.scala:3)
	at app.main(App.scala:3)
Caused by: java.lang.ClassNotFoundException: lib$
	at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
	... 3 more

Expected behaviour
no crash - program prints 23

@bishabosha bishabosha added the bug Something isn't working label Oct 21, 2022
@bishabosha
Copy link
Contributor Author

bishabosha commented Oct 21, 2022

maybe this is not an important goal because the old scala command never had a compile subcommand. However if in the future it was planned to have scalac underneath use scala-cli then this issue would be relevant

@Gedochao Gedochao added the scalac compatibility Issues tied with compatibility with the scalac (compiler) command. label Oct 24, 2022
@lwronski lwronski added the SIP-46 All the issues related to SIP-46 to turn Scala CLI into the official scala runner command. label Nov 2, 2022
@Gedochao Gedochao assigned Gedochao and unassigned Gedochao Dec 7, 2022
@clutroth clutroth assigned clutroth and unassigned Gedochao Dec 7, 2022
@Gedochao Gedochao linked a pull request Dec 8, 2022 that will close this issue
@tgodzik tgodzik moved this to Done in Scala CLI Board Jun 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers scalac compatibility Issues tied with compatibility with the scalac (compiler) command. SIP-46 All the issues related to SIP-46 to turn Scala CLI into the official scala runner command. Warsaw Scala Spree
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants