Skip to content

Handle $asInstanceOf$ in Splicer #6844

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
Jul 24, 2019
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
9 changes: 6 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/Splicer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,12 @@ object Splicer {
val staticMethodCall = interpretedStaticMethodCall(fn.symbol.owner, fn.symbol)
staticMethodCall(args.flatten.map(interpretTree))
} else if (fn.qualifier.symbol.is(Module) && fn.qualifier.symbol.isStatic) {
val staticMethodCall = interpretedStaticMethodCall(fn.qualifier.symbol.moduleClass, fn.symbol)
staticMethodCall(args.flatten.map(interpretTree))
if (fn.name == nme.asInstanceOfPM) {
interpretModuleAccess(fn.qualifier.symbol)
} else {
val staticMethodCall = interpretedStaticMethodCall(fn.qualifier.symbol.moduleClass, fn.symbol)
staticMethodCall(args.flatten.map(interpretTree))
}
} else if (env.contains(fn.name)) {
env(fn.name)
} else if (tree.symbol.is(InlineProxy)) {
Expand Down Expand Up @@ -265,7 +269,6 @@ object Splicer {

val name = getDirectName(fn.info.finalResultType, fn.name.asTermName)
val method = getMethod(clazz, name, paramsSig(fn))

(args: List[Object]) => stopIfRuntimeException(method.invoke(inst, args: _*))
}

Expand Down
12 changes: 12 additions & 0 deletions tests/run-macros/dollar-asInstanceOf-dollar/1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import scala.quoted._
import scala.deriving._

case class Box[A](x: A)

object Macro {
inline def foo[X[_]](implicit inline m: Mirror { type MirroredType = X }): Int =
${ fooImpl }

def fooImpl[X[_]](implicit m: Mirror { type MirroredType = X }, qc: QuoteContext): Expr[Int] =
'{ 1 }
}
4 changes: 4 additions & 0 deletions tests/run-macros/dollar-asInstanceOf-dollar/2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
object Test {
def main(args: Array[String]): Unit =
assert(Macro.foo[Box] == 1)
}