Macro info logging bug?

I’ve noticed that if I call c.info(pos, "message", force = false) inside a macro, it prints out on compilation despite the force parameter. The docs say that should mean the message is suppressed.

Here is some example code which does it:

import scala.reflect.macros.Context
import scala.language.experimental.macros

import scala.reflect.macros.blackbox

object Macros {
  def hello: Unit = macro helloImpl

  def helloImpl(c: blackbox.Context): c.Expr[Unit] = {
    import c.universe._
    c.info(c.enclosingPosition, "Message!", force = false)
  }
}

[INFO] <filepath> Message! is always logged, with force = true and force = false.

Note this only happens on sbt compile - it does not happen in a repl.

I’ve tried digging through the source scala code to find out why it’s doing this, but without an IDE it’s not very navigable.

Could anyone more knowledgeable point me in the right direction? I know it calls info in scala.tools.nsc.reporters.Reporter, which then calls some implementation of info0, but for the life of me I cannot find which one. I’ve tagged every implementation of info0 and none are called.

Hi James,

It seems you cannot rely on a specific behavior with respect to that parameter. The doc says that messages may be suppressed, without specifying when they are or aren’t.

In particular, the ContextReporter ignores the parameter.

Cheers: Lukas

Thanks for the reply Lukas.

Regarding the ‘may’ in the documentation, you’re right it is ambiguous.

So it is expected behaviour that all internal logging of all macros is exposed to the end user during compilation? That’s not great behaviour in my opinion. Perhaps I can make this a feature request instead of a bug…

Maybe c.settings works for your use-case? See https://github.com/scala/scala/blob/v2.12.3/src/reflect/scala/reflect/macros/Infrastructure.scala#L14-L17

@Irytz How does that help? Also this is not the only case where logging fails. It also failed in implicit macro:

Can’t believe it still doesn’t work after 4 years

As of 2.13, the reflection doc is not up-to-date.

force has been ignored since 2.13.1. echo should be preferred to info.

The doc mentioned by the linked SO says that the reporting behavior may be intended:

An error in an expansion of a whitebox implicit macro will just remove the macro from the list of implicit candidates in the current implicit search, without ever reporting an actual error to the user.

(I have not experimented yet.)

I assume the suggestion about macro settings is to let the user request verbose output from a blackbox macro via echo, instead of using info and expecting it to honor a global -verbose flag.