Skip to content

Commit 2e4662e

Browse files
committed
Fix #9100: Add error when experimental macros are not enabled
1 parent 345c8bc commit 2e4662e

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

compiler/src/dotty/tools/dotc/config/Feature.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ object Feature:
6060
def dependentEnabled(using Context) =
6161
enabled(nme.dependent, defn.LanguageExperimentalModule.moduleClass)
6262

63+
def scala2ExperimentalMacroEnabled(using Context) =
64+
enabled("macros".toTermName, defn.LanguageExperimentalModule.moduleClass)
65+
6366
def sourceVersionSetting(using Context): SourceVersion =
6467
SourceVersion.valueOf(ctx.settings.source.value)
6568

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3581,6 +3581,13 @@ class Typer extends Namer
35813581
}
35823582
}
35833583
if ctx.phase.isTyper then
3584+
if !config.Feature.scala2ExperimentalMacroEnabled then
3585+
ctx.error(
3586+
"""Scala 2 macro definition needs to be enabled
3587+
|by making the implicit value scala.language.experimental.macros visible.
3588+
|This can be achieved by adding the import clause 'import scala.language.experimental.macros'
3589+
|or by setting the compiler option -language:experimental.macros.
3590+
""".stripMargin, call.sourcePos)
35843591
call match
35853592
case call: untpd.Ident =>
35863593
typedIdent(call, defn.AnyType)

tests/neg/i9100.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object FooMacros {
2+
def foo[T]: String = macro Foo.fooImpl[T] // error: Scala 2 macro definition needs to be enabled
3+
}

tests/pos/macro.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import scala.language.experimental.macros
12
class A {
23
def foo: Int = macro ???
34
inline def foo: Int = ???

0 commit comments

Comments
 (0)