diff --git a/compiler/src/dotty/tools/dotc/quoted/Interpreter.scala b/compiler/src/dotty/tools/dotc/quoted/Interpreter.scala index 38cecb7953b8..7c8262ecbf00 100644 --- a/compiler/src/dotty/tools/dotc/quoted/Interpreter.scala +++ b/compiler/src/dotty/tools/dotc/quoted/Interpreter.scala @@ -32,10 +32,15 @@ import dotty.tools.dotc.reporting.Message import dotty.tools.repl.AbstractFileClassLoader /** Tree interpreter for metaprogramming constructs */ -class Interpreter(pos: SrcPos, classLoader: ClassLoader)(using Context): +class Interpreter(pos: SrcPos, classLoader0: ClassLoader)(using Context): import Interpreter._ import tpd._ + val classLoader = + if ctx.owner.topLevelClass.name.startsWith(str.REPL_SESSION_LINE) then + new AbstractFileClassLoader(ctx.settings.outputDir.value, classLoader0) + else classLoader0 + /** Local variable environment */ type Env = Map[Symbol, Object] def emptyEnv: Env = Map.empty @@ -157,18 +162,12 @@ class Interpreter(pos: SrcPos, classLoader: ClassLoader)(using Context): args.toSeq private def interpretedStaticMethodCall(moduleClass: Symbol, fn: Symbol, args: List[Object]): Object = { - val (inst, clazz) = - try - if (moduleClass.name.startsWith(str.REPL_SESSION_LINE)) - (null, loadReplLineClass(moduleClass)) - else { - val inst = loadModule(moduleClass) - (inst, inst.getClass) - } + val inst = + try loadModule(moduleClass) catch case MissingClassDefinedInCurrentRun(sym) => suspendOnMissing(sym, pos) - + val clazz = inst.getClass val name = fn.name.asTermName val method = getMethod(clazz, name, paramsSig(fn)) stopIfRuntimeException(method.invoke(inst, args: _*), method) diff --git a/compiler/test-resources/repl-macros/i15104a b/compiler/test-resources/repl-macros/i15104a new file mode 100644 index 000000000000..92e82928b509 --- /dev/null +++ b/compiler/test-resources/repl-macros/i15104a @@ -0,0 +1,7 @@ +scala> import scala.quoted._ +scala> object Foo { def macroImpl(using Quotes) = Expr(1) } +// defined object Foo +scala> inline def foo = ${ Foo.macroImpl } +def foo: Int +scala> foo +val res0: Int = 1 diff --git a/compiler/test-resources/repl-macros/i15104b b/compiler/test-resources/repl-macros/i15104b new file mode 100644 index 000000000000..ebbdb2402076 --- /dev/null +++ b/compiler/test-resources/repl-macros/i15104b @@ -0,0 +1,5 @@ +scala> import scala.quoted._ +scala> object Foo { def macroImpl(using Quotes) = Expr(1); inline def foo = ${ Foo.macroImpl } } +// defined object Foo +scala> Foo.foo +val res0: Int = 1 diff --git a/compiler/test-resources/repl-macros/i15104c b/compiler/test-resources/repl-macros/i15104c new file mode 100644 index 000000000000..482b9487c9d9 --- /dev/null +++ b/compiler/test-resources/repl-macros/i15104c @@ -0,0 +1,7 @@ +scala> import scala.quoted._ +scala> def macroImpl(using Quotes) = Expr(1) +def macroImpl(using x$1: quoted.Quotes): quoted.Expr[Int] +scala> inline def foo = ${ macroImpl } +def foo: Int +scala> foo +val res0: Int = 1 diff --git a/compiler/test-resources/repl-macros/i5551 b/compiler/test-resources/repl-macros/i5551 index fb039ed19dd6..d71251e9a824 100644 --- a/compiler/test-resources/repl-macros/i5551 +++ b/compiler/test-resources/repl-macros/i5551 @@ -1,8 +1,7 @@ scala> import scala.quoted._ scala> def assertImpl(expr: Expr[Boolean])(using q: Quotes) = '{ if !($expr) then throw new AssertionError("failed assertion")} def assertImpl - (expr: quoted.Expr[Boolean]) - (using q: quoted.Quotes): quoted.Expr[Unit] + (expr: quoted.Expr[Boolean])(using q: quoted.Quotes): quoted.Expr[Unit] scala> inline def assert(expr: => Boolean): Unit = ${ assertImpl('{expr}) } def assert(expr: => Boolean): Unit diff --git a/compiler/test/dotty/tools/repl/ScriptedTests.scala b/compiler/test/dotty/tools/repl/ScriptedTests.scala index 5c3a32cd40f8..dc809228e86b 100644 --- a/compiler/test/dotty/tools/repl/ScriptedTests.scala +++ b/compiler/test/dotty/tools/repl/ScriptedTests.scala @@ -3,12 +3,16 @@ package tools package repl import org.junit.Test +import org.junit.experimental.categories.Category /** Runs all tests contained in `compiler/test-resources/repl/` */ class ScriptedTests extends ReplTest { @Test def replTests = scripts("/repl").foreach(testFile) + @Category(Array(classOf[BootstrappedOnlyTests])) + @Test def replMacrosTests = scripts("/repl-macros").foreach(testFile) + @Test def typePrinterTests = scripts("/type-printer").foreach(testFile) }