Skip to content

All logging functions in scala.reflect.macros.FrontEnds don't work in implicit macros pattern #12388

Open
@tribbloid

Description

@tribbloid

reproduction steps

Main example:

https://stackoverflow.com/questions/67328769/in-scala-2-13-how-to-log-information-warning-error-reliably-in-macro

using Scala 2.13.5, if you use any macro logging function in a macro, e.g.

class EmitMsg[T] {}

object EmitMsg {

  implicit def emit[A]: EmitMsg[A] = macro Macros.emit[A]

  final class Macros(val c: whitebox.Context) {

    def emit[A: c.WeakTypeTag]: c.Tree = {
      c.abort(c.enclosingPosition, "ERROR!")
    }
  }
}

The logging will only be triggered if the macro function (in this case EmitMsg.emit) was called directly, if it is called as part of an implicit macros pattern (https://docs.scala-lang.org/overviews/macros/implicits.html), it will be ignored. Namely, all error message degrades to "implicit not found" message, and all info & warning message won't be logged or displayed anywhere.

problem

Give the ubiquity of implicit macros pattern, this issue may seriously degrade the capability of macro system.

This issue is also blocking my PR for singleton-ops:

fthomas/singleton-ops#186

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions