Skip to content

Commit c34826d

Browse files
committed
Merge pull request scala#3651 from xeno-by/ticket/8437
SI-8437 macro runtime now also picks inherited macro implementations
2 parents c765537 + 9326264 commit c34826d

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

src/compiler/scala/reflect/macros/runtime/JavaReflectionRuntimes.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ trait JavaReflectionRuntimes {
1414

1515
def resolveJavaReflectionRuntime(classLoader: ClassLoader): MacroRuntime = {
1616
val implClass = Class.forName(className, true, classLoader)
17-
val implMeths = implClass.getDeclaredMethods.find(_.getName == methName)
17+
val implMeths = implClass.getMethods.find(_.getName == methName)
1818
// relies on the fact that macro impls cannot be overloaded
1919
// so every methName can resolve to at maximum one method
2020
val implMeth = implMeths getOrElse { throw new NoSuchMethodException(s"$className.$methName") }

test/files/run/t8437.check

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
5
2+
5

test/files/run/t8437/Macros_1.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import scala.language.experimental.macros
2+
import scala.reflect.macros._
3+
4+
abstract class AbstractBundle(val c: blackbox.Context) {
5+
import c.Expr
6+
import c.universe._
7+
def foo: Expr[Int] = Expr[Int](q"5")
8+
}
9+
10+
class ConcreteBundle(override val c: blackbox.Context) extends AbstractBundle(c) {
11+
import c.Expr
12+
val bar: Expr[Int] = foo
13+
}
14+
15+
object InvokeBundle {
16+
def foo: Int = macro ConcreteBundle.foo // nope
17+
def bar: Int = macro ConcreteBundle.bar // yep
18+
}

test/files/run/t8437/Test_2.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
object Test extends App {
2+
println(InvokeBundle.foo)
3+
println(InvokeBundle.bar)
4+
}

0 commit comments

Comments
 (0)