scala-cli icon indicating copy to clipboard operation
scala-cli copied to clipboard

Missing diagnostics from macros

Open tgodzik opened this issue 2 years ago • 3 comments

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())))

tgodzik avatar Nov 10 '23 16:11 tgodzik

This is a duplicate of #357, I think.

SethTisue avatar Nov 10 '23 21:11 SethTisue

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.

tgodzik avatar Nov 13 '23 14:11 tgodzik

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.

SethTisue avatar Jan 24 '24 00:01 SethTisue