Skip to content

Commit f1db208

Browse files
committed
Improve non-static macro implementation error message
If non-static inline accessor is generated we do not we can tell the user why they cannot access the macro implementation this way. Currently we do not have a clean way to fix this code, but in the future [SIP-58](scala/improvement-proposals#58) would introduce a way to not generate this accessor. Fixes #15413
1 parent ca6a80e commit f1db208

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

compiler/src/dotty/tools/dotc/transform/Splicer.scala

+8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import dotty.tools.dotc.quoted.{PickledQuotes, QuoteUtils}
3131

3232
import scala.quoted.Quotes
3333
import scala.quoted.runtime.impl._
34+
import dotty.tools.dotc.core.NameKinds
3435

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

218+
case Call(fn, args) if fn.symbol.name.is(NameKinds.InlineAccessorName) =>
219+
// TODO suggest use of @binaryAPI one we have the annotation
220+
report.error(
221+
i"""Macro implementation is not statically accessible.
222+
|
223+
|Non-static inline accessor was generated in ${fn.symbol.owner}
224+
|""".stripMargin, tree.srcPos)
217225
case _ =>
218226
report.error(
219227
"""Malformed macro.

tests/neg-macros/i15413.check

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-- Error: tests/neg-macros/i15413.scala:4:22 ---------------------------------------------------------------------------
2+
4 | inline def foo = ${ Macro.fooImpl } // error
3+
| ^^^^^^^^^^^^^
4+
| Macro implementation is not statically accessible.
5+
|
6+
| Non-static inline accessor was generated in class Macro

tests/neg-macros/i15413.scala

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import scala.quoted.*
2+
3+
class Macro:
4+
inline def foo = ${ Macro.fooImpl } // error
5+
6+
object Macro:
7+
private def fooImpl(using Quotes) = '{}

0 commit comments

Comments
 (0)