Skip to content

Macro MatchError on EmptyTree #9227

Closed
@FabioPinheiro

Description

@FabioPinheiro

Minimized code

REPL crash with a MatchError on EmptyTree. If we do a single call on the REPL

import scala.quoted._                                                                                                                                                                                                                  
inline def myMacro[T]: Unit = ${ myMacroImpl[T] }
def myMacroImpl[T](using qctx: QuoteContext): Expr[Unit] = '{}
println(myMacro[Int])

I was expecting to fail compilation after calling the macro with the error

Cannot call macro method myMacroImpl defined in the same source file
  | This location contains code that was inlined from rs$line$1:4

Instead, it seems that an EmptyTree is returned during macro expansion.
I assume it tries to continue the compilation of the line with that.

Output

Exception in thread "main" scala.MatchError: EmptyTree (of class dotty.tools.dotc.ast.Trees$EmptyTree)
	at dotty.tools.repl.CollectTopLevelImports.topLevelImports$1(CollectTopLevelImports.scala:23)
	at dotty.tools.repl.CollectTopLevelImports.run(CollectTopLevelImports.scala:28)
	at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:318)
	at scala.collection.immutable.List.map(List.scala:246)
	at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:319)
	at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:180)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
	at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
	at dotty.tools.dotc.Run.runPhases$5(Run.scala:190)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:198)
	at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:64)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:205)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:147)
	at dotty.tools.repl.ReplCompiler.runCompilationUnit(ReplCompiler.scala:156)
	at dotty.tools.repl.ReplCompiler.compile(ReplCompiler.scala:166)
	at dotty.tools.repl.ReplDriver.compile(ReplDriver.scala:231)
	at dotty.tools.repl.ReplDriver.interpret(ReplDriver.scala:195)
	at dotty.tools.repl.ReplDriver.loop$1(ReplDriver.scala:128)
	at dotty.tools.repl.ReplDriver.runUntilQuit$$anonfun$1(ReplDriver.scala:131)
	at dotty.tools.repl.ReplDriver.withRedirectedOutput(ReplDriver.scala:150)
	at dotty.tools.repl.ReplDriver.runUntilQuit(ReplDriver.scala:131)
	at dotty.tools.repl.Main$.main(Main.scala:6)
	at dotty.tools.repl.Main.main(Main.scala)
[error] Nonzero exit code returned from runner: 1
[error] (dotty-compiler / Compile / runMain) Nonzero exit code returned from runner: 1

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions