Skip to content
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

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

Open
tribbloid opened this issue May 1, 2021 · 3 comments
Labels
Milestone

Comments

@tribbloid
Copy link

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

@som-snytt
Copy link

I think this duplicates #10946 where the feature request is for a dynamic error message customized by the macro.

This would hook into the standard implicitNotFound machinery. Per the linked overview:

A nice thing about implicit macros is that they seamlessly meld into the pre-existing infrastructure of implicit search.

@tribbloid
Copy link
Author

@som-snytt Thanks a lot, I can't find in the post which mentioned macro anywhere (or compilet-time context warning/info). It may be possible to merge these 2 issues into one, as the "shading" of error message could happen twice in a row:

  • type-mismatch error shading implicit not found error
  • implicit not found error shading macro context error

@dwijnand dwijnand changed the title All logging functions in scala.reflection.macros.FrontEnds doesn't work in implicit macros pattern All logging functions in scala.reflect.macros.FrontEnds doesn't work in implicit macros pattern Jun 4, 2021
@dwijnand dwijnand changed the title All logging functions in scala.reflect.macros.FrontEnds doesn't work in implicit macros pattern All logging functions in scala.reflect.macros.FrontEnds don't work in implicit macros pattern Jun 4, 2021
@SethTisue SethTisue added this to the Backlog milestone Jun 4, 2021
@dwijnand dwijnand added the macros label Jun 4, 2021
@SethTisue
Copy link
Member

It appears that (especially when considered in combination with #10946) some design thinking would be required to address this.

I wonder what Scala 3 does.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants