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

Improve non-static macro implementation error message #18405

Merged
merged 2 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions compiler/src/dotty/tools/dotc/transform/Splicer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import dotty.tools.dotc.quoted.{PickledQuotes, QuoteUtils}

import scala.quoted.Quotes
import scala.quoted.runtime.impl._
import dotty.tools.dotc.core.NameKinds

/** Utility class to splice quoted expressions */
object Splicer {
Expand Down Expand Up @@ -214,6 +215,13 @@ object Splicer {
report.error("Macro cannot be implemented with an `inline` method", fn.srcPos)
args.flatten.foreach(checkIfValidArgument)

case Call(fn, args) if fn.symbol.name.is(NameKinds.InlineAccessorName) =>
// TODO suggest use of @binaryAPI once we have the annotation
report.error(
i"""Macro implementation is not statically accessible.
|
|Non-static inline accessor was generated in ${fn.symbol.owner}
|""".stripMargin, tree.srcPos)
case _ =>
report.error(
"""Malformed macro.
Expand Down
6 changes: 6 additions & 0 deletions tests/neg-macros/i15413.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
-- Error: tests/neg-macros/i15413.scala:4:22 ---------------------------------------------------------------------------
4 | inline def foo = ${ Macro.fooImpl } // error
| ^^^^^^^^^^^^^
| Macro implementation is not statically accessible.
|
| Non-static inline accessor was generated in class Macro
7 changes: 7 additions & 0 deletions tests/neg-macros/i15413.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import scala.quoted.*

class Macro:
inline def foo = ${ Macro.fooImpl } // error

object Macro:
private def fooImpl(using Quotes) = '{}
Loading