Skip to content

Commit 08dbb30

Browse files
committed
Fix #4492: Load module instance instead of calling static methods
1 parent 3e1ce3b commit 08dbb30

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ package transform
33

44
import java.io.{PrintWriter, StringWriter}
55
import java.lang.reflect.Method
6-
import java.net.URLClassLoader
76

87
import dotty.tools.dotc.ast.tpd
98
import dotty.tools.dotc.core.Contexts._
109
import dotty.tools.dotc.core.Decorators._
1110
import dotty.tools.dotc.core.Flags.Package
1211
import dotty.tools.dotc.core.NameKinds.FlatName
1312
import dotty.tools.dotc.core.Names.Name
13+
import dotty.tools.dotc.core.StdNames.str.MODULE_INSTANCE_FIELD
1414
import dotty.tools.dotc.core.quoted._
1515
import dotty.tools.dotc.core.Types._
1616
import dotty.tools.dotc.core.Symbols._
@@ -128,7 +128,9 @@ object Splicer {
128128
private def loadModule(sym: Symbol): (Class[_], Object) = {
129129
if (sym.owner.is(Package)) {
130130
// is top level object
131-
(loadClass(sym.companionModule.fullName), null)
131+
val moduleClass = loadClass(sym.fullName)
132+
val moduleInstance = moduleClass.getField(MODULE_INSTANCE_FIELD).get(null)
133+
(moduleClass, moduleInstance)
132134
} else {
133135
// nested object in an object
134136
val clazz = loadClass(sym.fullNameSeparated(FlatName))

tests/run/i4492.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ok

tests/run/i4492/quoted_1.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
trait Index
3+
4+
object Index {
5+
inline def succ(prev: Index): Unit = ~{ '(println("Ok")) }
6+
}

tests/run/i4492/quoted_2.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
object Test {
3+
def main(args: Array[String]): Unit = {
4+
Index.succ(null)
5+
}
6+
}

0 commit comments

Comments
 (0)