Skip to content

Commit 8bd0075

Browse files
Merge pull request #6844 from dotty-staging/handle-$asInstanceOf$
Handle $asInstanceOf$ in Splicer
2 parents 3540085 + f8a5424 commit 8bd0075

File tree

3 files changed

+22
-3
lines changed

3 files changed

+22
-3
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,12 @@ object Splicer {
193193
val staticMethodCall = interpretedStaticMethodCall(fn.symbol.owner, fn.symbol)
194194
staticMethodCall(args.flatten.map(interpretTree))
195195
} else if (fn.qualifier.symbol.is(Module) && fn.qualifier.symbol.isStatic) {
196-
val staticMethodCall = interpretedStaticMethodCall(fn.qualifier.symbol.moduleClass, fn.symbol)
197-
staticMethodCall(args.flatten.map(interpretTree))
196+
if (fn.name == nme.asInstanceOfPM) {
197+
interpretModuleAccess(fn.qualifier.symbol)
198+
} else {
199+
val staticMethodCall = interpretedStaticMethodCall(fn.qualifier.symbol.moduleClass, fn.symbol)
200+
staticMethodCall(args.flatten.map(interpretTree))
201+
}
198202
} else if (env.contains(fn.name)) {
199203
env(fn.name)
200204
} else if (tree.symbol.is(InlineProxy)) {
@@ -265,7 +269,6 @@ object Splicer {
265269

266270
val name = getDirectName(fn.info.finalResultType, fn.name.asTermName)
267271
val method = getMethod(clazz, name, paramsSig(fn))
268-
269272
(args: List[Object]) => stopIfRuntimeException(method.invoke(inst, args: _*))
270273
}
271274

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import scala.quoted._
2+
import scala.deriving._
3+
4+
case class Box[A](x: A)
5+
6+
object Macro {
7+
inline def foo[X[_]](implicit inline m: Mirror { type MirroredType = X }): Int =
8+
${ fooImpl }
9+
10+
def fooImpl[X[_]](implicit m: Mirror { type MirroredType = X }, qc: QuoteContext): Expr[Int] =
11+
'{ 1 }
12+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object Test {
2+
def main(args: Array[String]): Unit =
3+
assert(Macro.foo[Box] == 1)
4+
}

0 commit comments

Comments
 (0)