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
527 stars 124 forks source link

Missing diagnostics from macros #2530

Closed tgodzik closed 1 day ago

tgodzik commented 7 months ago

Version(s) 1.0.5

Describe the bug It seems that some of the diagnostics sent from macros compiled in Bloop are missing in the Scala CLI output, but they are present in the IDE output, which means at some point they were also in Scala CLI

To Reproduce

// Main.scala
//> using scala 2.13.12
//> using dep org.scala-lang:scala-reflect:2.13.12

package example

import scala.reflect.macros.blackbox
import scala.language.experimental.macros

object Scala2Example {
  def macroMethod[A](a: A): String =
    macro Scala2Example.macroMethodImpl[A]

  def macroMethodImpl[A: c.WeakTypeTag](
    c: blackbox.Context
  )(a: c.Expr[A]): c.Expr[String] = {
    import c.universe._
    val output = s"""${show(a.tree)}
                    |${showCode(a.tree)}
                    |${showRaw(a.tree)}
                    |${weakTypeTag[A]}
                    |${weakTypeOf[A]}
                    |${showRaw(weakTypeOf[A])}""".stripMargin
    c.echo(c.enclosingPosition, output)
    c.warning(c.enclosingPosition, "example error message")
    c.abort(c.enclosingPosition, "example error message")
  }
}
// Test.test.scala
//> using test.dep org.scalameta::munit::1.0.0-M10

package example

class Tests extends munit.FunSuite {
  test("macro works OK") {
    Scala2Example.macroMethod(1 -> "test")
  }
}

This is printing:

Compiling project (test, Scala 2.13.12, JVM (17))
[error] ./Test.test.scala:7:5
[error] example error message
[error]     Scala2Example.macroMethod(1 -> "test")
[error]     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error compiling project (test, Scala 2.13.12, JVM (17))
Compilation failed

Expected behaviour It should also print (I think the severity is different at hint level)

scala.Predef.ArrowAssoc[Int](1).->[String](\"test\")\nscala.Predef.ArrowAssoc[Int](1).->[String](\"test\")\nApply(TypeApply(Select(Apply(TypeApply(Select(Select(Ident(scala), scala.Predef), TermName(\"ArrowAssoc\")), List(TypeTree())), List(Literal(Constant(1)))), TermName(\"$minus$greater\")), List(TypeTree())), List(Literal(Constant(\"test\"))))\nWeakTypeTag[(Int, String)]\n(Int, String)\nTypeRef(ThisType(scala), scala.Tuple2, List(TypeRef(ThisType(scala), scala.Int, List()), TypeRef(ThisType(java.lang), java.lang.String, List())))
SethTisue commented 7 months ago

This is a duplicate of #357, I think.

tgodzik commented 7 months ago

That is different, since the stacktraces are not being sent at all while these are normal diagnostics. They are printed by Metals, but not printed by scala-cli, which should be quick to fix.

SethTisue commented 5 months ago

I see.

Note that compiler plugins are affected as well. I am debugging a Scala 3 compiler plugin, and the debugging output from the plugin vanishes. --server=false makes the output appear as expected.