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

Improve Scala compiler settings integration #2867

Open
lrytz opened this issue Apr 19, 2024 · 2 comments
Open

Improve Scala compiler settings integration #2867

lrytz opened this issue Apr 19, 2024 · 2 comments
Labels
enhancement New feature or request missing feature Something should have been implemented, but wasn't. scalac compatibility Issues tied with compatibility with the scalac (compiler) command.

Comments

@lrytz
Copy link

lrytz commented Apr 19, 2024

Sorry for another ticket like #2779 / #753... I understand there are difficulties how to handle this, but the user experience can probably still be improved.

There are compiler options not forwarded by the compiler, for example

➜ sandbox scala-cli compile --server=false C.scala
-- [E007] Type Mismatch Error: /Users/luc/code/scala/scala13/sandbox/C.scala:2:15
...
  | longer explanation available when compiling with `-explain`
1 error found
Compilation failed

➜ sandbox scala-cli compile --server=false C.scala -explain
Unrecognized argument: -explain

To list all available options, run
  scala-cli compile --help

When a user installs Scala, runs the compiler, and the compiler tells them to add a flag (-explain), they should not need to figure out that they actually need to do -O -explain.

The approach currently is for scala-cli to forward known compiler flags. Would it be possible to pass all unrecognized arguments to the compiler by default (for compile / repl / doc)?

As a backstop, a static hint in the "Unrecognized argument" message could help. If scala-cli compile / repl / doc gets an unrecognized argument, it could suggest "Use -O ${unrecognized} to pass the argument to the Scala compiler".


Another confusing situation is because the compiler is not invoked when there are no souce files. So scala-cli compile -S 2 C.scala -opt:help works, but scala-cli compile -S 2 -opt:help doesn't.


Finally, in Scala 2 at least there are compiler options that support space separated arguments, for example -Vopt _ or -Vprint-args args.txt. The first makes scala-cli hang, the second gives an error message ([error] args.txt: unrecognized source type).

It's again not obvious for the user what's going on.

@lrytz lrytz added the bug Something isn't working label Apr 19, 2024
@Gedochao
Copy link
Contributor

Gedochao commented Apr 19, 2024

Would it be possible to pass all unrecognized arguments to the compiler by default (for compile / repl / doc)?

I'm not a fan of this, as it may cause unexpected results. Many compiler options take arguments, which then have to be correctly parsed by Scala CLI. I think it would cause more confusion than merit.

A more sustainable solution would be to rely on the Scala compiler Settings API, as implemented in scala/scala3#19766
Doing so is the long-term plan for solving this issue.

I suppose this would only solve options for the Scala 3 compiler (which is the priority).
Optimally, Scala 2 could have similar API in the future, which we could use, maybe(thoughts, @lrytz?)

I think we can use this issue to track this, I was hoping to work on this soon.

@Gedochao Gedochao changed the title More about arguments not forwarded to the compiler Improve Scala compiler settings integration Apr 19, 2024
@Gedochao Gedochao added enhancement New feature or request scalac compatibility Issues tied with compatibility with the scalac (compiler) command. missing feature Something should have been implemented, but wasn't. and removed bug Something isn't working labels Apr 19, 2024
@lrytz
Copy link
Author

lrytz commented Apr 22, 2024

I agree the best solution is when scala-cli has a way to talk to the compiler and understand which settings it accepts. That should be doable for Scala 2 as well, I'm happy to help work on that.

If scala-cli becomes default / more prominent before that happens, adding some generic information to scala-cli's Unrecognized argument message seems very helpful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request missing feature Something should have been implemented, but wasn't. scalac compatibility Issues tied with compatibility with the scalac (compiler) command.
Projects
None yet
Development

No branches or pull requests

2 participants