From 08dbb305ffbadd2ec952d1c32050ea1da5d0eb07 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Wed, 23 May 2018 15:17:54 +0200 Subject: [PATCH] Fix #4492: Load module instance instead of calling static methods --- compiler/src/dotty/tools/dotc/transform/Splicer.scala | 6 ++++-- tests/run/i4492.check | 1 + tests/run/i4492/quoted_1.scala | 6 ++++++ tests/run/i4492/quoted_2.scala | 6 ++++++ 4 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 tests/run/i4492.check create mode 100644 tests/run/i4492/quoted_1.scala create mode 100644 tests/run/i4492/quoted_2.scala diff --git a/compiler/src/dotty/tools/dotc/transform/Splicer.scala b/compiler/src/dotty/tools/dotc/transform/Splicer.scala index 51f89b10e821..9a4e96a0ad0f 100644 --- a/compiler/src/dotty/tools/dotc/transform/Splicer.scala +++ b/compiler/src/dotty/tools/dotc/transform/Splicer.scala @@ -3,7 +3,6 @@ package transform import java.io.{PrintWriter, StringWriter} import java.lang.reflect.Method -import java.net.URLClassLoader import dotty.tools.dotc.ast.tpd import dotty.tools.dotc.core.Contexts._ @@ -11,6 +10,7 @@ import dotty.tools.dotc.core.Decorators._ import dotty.tools.dotc.core.Flags.Package import dotty.tools.dotc.core.NameKinds.FlatName import dotty.tools.dotc.core.Names.Name +import dotty.tools.dotc.core.StdNames.str.MODULE_INSTANCE_FIELD import dotty.tools.dotc.core.quoted._ import dotty.tools.dotc.core.Types._ import dotty.tools.dotc.core.Symbols._ @@ -128,7 +128,9 @@ object Splicer { private def loadModule(sym: Symbol): (Class[_], Object) = { if (sym.owner.is(Package)) { // is top level object - (loadClass(sym.companionModule.fullName), null) + val moduleClass = loadClass(sym.fullName) + val moduleInstance = moduleClass.getField(MODULE_INSTANCE_FIELD).get(null) + (moduleClass, moduleInstance) } else { // nested object in an object val clazz = loadClass(sym.fullNameSeparated(FlatName)) diff --git a/tests/run/i4492.check b/tests/run/i4492.check new file mode 100644 index 000000000000..7326d9603970 --- /dev/null +++ b/tests/run/i4492.check @@ -0,0 +1 @@ +Ok diff --git a/tests/run/i4492/quoted_1.scala b/tests/run/i4492/quoted_1.scala new file mode 100644 index 000000000000..67e68d59c1e7 --- /dev/null +++ b/tests/run/i4492/quoted_1.scala @@ -0,0 +1,6 @@ + +trait Index + +object Index { + inline def succ(prev: Index): Unit = ~{ '(println("Ok")) } +} diff --git a/tests/run/i4492/quoted_2.scala b/tests/run/i4492/quoted_2.scala new file mode 100644 index 000000000000..7b1ed8119507 --- /dev/null +++ b/tests/run/i4492/quoted_2.scala @@ -0,0 +1,6 @@ + +object Test { + def main(args: Array[String]): Unit = { + Index.succ(null) + } +}