Skip to content

Fix #4492: Load module instance instead of calling static methods #4571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/Splicer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ 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._
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._
Expand Down Expand Up @@ -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))
Expand Down
1 change: 1 addition & 0 deletions tests/run/i4492.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ok
6 changes: 6 additions & 0 deletions tests/run/i4492/quoted_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

trait Index

object Index {
inline def succ(prev: Index): Unit = ~{ '(println("Ok")) }
}
6 changes: 6 additions & 0 deletions tests/run/i4492/quoted_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

object Test {
def main(args: Array[String]): Unit = {
Index.succ(null)
}
}