Skip to content

Commit 902f4cb

Browse files
Merge pull request #4571 from dotty-staging/fix-#4492
Fix #4492: Load module instance instead of calling static methods
2 parents 6876240 + 08dbb30 commit 902f4cb

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import dotty.tools.dotc.core.Decorators._
1010
import dotty.tools.dotc.core.Flags.Package
1111
import dotty.tools.dotc.core.NameKinds.FlatName
1212
import dotty.tools.dotc.core.Names.Name
13+
import dotty.tools.dotc.core.StdNames.str.MODULE_INSTANCE_FIELD
1314
import dotty.tools.dotc.core.quoted._
1415
import dotty.tools.dotc.core.Types._
1516
import dotty.tools.dotc.core.Symbols._
@@ -130,7 +131,9 @@ object Splicer {
130131
private def loadModule(sym: Symbol): (Class[_], Object) = {
131132
if (sym.owner.is(Package)) {
132133
// is top level object
133-
(loadClass(sym.companionModule.fullName), null)
134+
val moduleClass = loadClass(sym.fullName)
135+
val moduleInstance = moduleClass.getField(MODULE_INSTANCE_FIELD).get(null)
136+
(moduleClass, moduleInstance)
134137
} else {
135138
// nested object in an object
136139
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)