Skip to content

//> using option "--explain" does nothing #1285

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

Closed
Kordyjan opened this issue Aug 25, 2022 · 2 comments · Fixed by #1830
Closed

//> using option "--explain" does nothing #1285

Kordyjan opened this issue Aug 25, 2022 · 2 comments · Fixed by #1830
Assignees
Labels
bug Something isn't working SIP-46 All the issues related to SIP-46 to turn Scala CLI into the official scala runner command.

Comments

@Kordyjan
Copy link

Kordyjan commented Aug 25, 2022

Version(s)
0.1.12

Describe the bug
//> using option "--explain" doesn't change the compilation output. Probably it has the same root cause as #1023. The problem goes away if we run scala-cli with --server=false.

To Reproduce
explain.scala:

//> using option "--explain"

class A

val i: Int = A()

Run scala-cli compile explain.scala. The output will be:

[error] ./explain.scala:5:14: Found:    A
[error] Required: Int
[error] val i: Int = A()
[error]              ^^^
Error compiling project (Scala 3.1.3, JVM)
Compilation failed

Expected behaviour

The output should look like this:

-- [E007] Type Mismatch Error: /Users/pmarks/projs/rep/explain.scala:5:14 ------
5 |val i: Int = A()
  |             ^^^
  |             Found:    A
  |             Required: Int
  |-----------------------------------------------------------------------------
  | Explanation (enabled by `-explain`)
  |- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  |
  | Tree: new A()
  | I tried to show that
  |   A
  | conforms to
  |   Int
  | but the comparison trace ended with `false`:
  |
  |   ==> A  <:  Int
  |   <== A  <:  Int = false
  |
  | The tests were made under the empty constraint
   -----------------------------------------------------------------------------
@lwronski lwronski added the bug Something isn't working label Sep 14, 2022
@Gedochao Gedochao added the SIP-46 All the issues related to SIP-46 to turn Scala CLI into the official scala runner command. label Sep 26, 2022
@lwronski lwronski self-assigned this Oct 27, 2022
@lwronski
Copy link
Contributor

@Kordyjan Thanks for reporting. I want to summarize this issue.

First of all, the explain message which you mention is generated here in scalac and set to a field rendered in Problem class.

From the bloop side, the rendered message are available and ready to use but it is skipped. In BSP there is no reasonable field in Diagnostic class to send rendered message. The rendered content isn't so important to the IDE and is probably for this reason the message isn't sent anywhere from bloop.

In scala-cli which uses bloop under the hood, the rendered message isn't available because bloop doesn't send this message.

There are at least two solutions of this problem:

  • modification of the BSP protocol to send rendered message to scala-cli
  • if the user passes the explain option to scala-cli, the scalac compiler will be automatically used, i.e. the --server=false flag will be set

@tgodzik
Copy link
Member

tgodzik commented Oct 31, 2022

It's also a bit weird that explain message is only available in the rendered message and not in for example usual message field. This doesn't allow tools to sensibly use that additional message and render in their own style. It's either you use render or you don't get it.

I would be better if this was added to some other field or as additional diagnostics. Not sure currently what would be the best solution, but it fits into the whole structured errors and actionable diagnostics debacle. Ideally explain message would be a field that is always available without running a second compilation or modifying the whole build definition.

prolativ added a commit to scala/scala3 that referenced this issue Feb 3, 2023
When the `-explain` flag was turned on, an explanation message wasn't
displayed in the Metals and Scala CLI. This was because both of these
tools only print the message from the
[Problem.message](https://github.com/lampepfl/dotty/blob/c0a7d128671d063a2b566abdaa08fe7fa83c2d06/sbt-bridge/src/dotty/tools/xsbt/Problem.java#L17)
field.

To resolve this issue, I attached the explanation content to the
`Problem.message` field, which will now be displayed in the Metals and
Scala CLI.

This PR addresses a
[issue](VirtusLab/scala-cli#1285) from
`scala-cli`.
@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 SIP-46 All the issues related to SIP-46 to turn Scala CLI into the official scala runner command.
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

4 participants