Skip to content

Commit 2f68297

Browse files
authored
Merge pull request #6521 from dotty-staging/fix-#6518-2
Fix #6518: Add type parameters to class type before asking for members
2 parents 512a760 + b3ef823 commit 2f68297

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

compiler/src/dotty/tools/dotc/tastyreflect/KernelImpl.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1556,7 +1556,11 @@ class KernelImpl(val rootContext: core.Contexts.Context, val rootPosition: util.
15561556
}
15571557

15581558
def ClassDefSymbol_methods(self: Symbol)(implicit ctx: Context): List[DefDefSymbol] = {
1559-
self.typeRef.allMembers.iterator.map(_.symbol).collect {
1559+
val classTpe = self.typeRef.appliedTo(self.typeParams.map { param =>
1560+
if (param.variance == -1) param.info.hiBound
1561+
else param.info.loBound
1562+
})
1563+
classTpe.allMembers.iterator.map(_.symbol).collect {
15601564
case sym if isMethod(sym) => sym.asTerm
15611565
}.toList
15621566
}

tests/run-macros/i6518.check

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
!=
2+
##
3+
$asInstanceOf$
4+
$isInstanceOf$
5+
==
6+
andThen
7+
apply
8+
asInstanceOf
9+
clone
10+
compose
11+
eq
12+
equals
13+
finalize
14+
getClass
15+
hashCode
16+
isInstanceOf
17+
ne
18+
notify
19+
notifyAll
20+
synchronized
21+
toString
22+
wait
23+
wait
24+
wait

tests/run-macros/i6518/Macro_1.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import scala.quoted._
2+
import scala.quoted.autolift._
3+
import scala.tasty._
4+
5+
object Macros {
6+
7+
inline def test(): String = ${ testImpl }
8+
9+
private def testImpl(implicit reflect: Reflection): Expr[String] = {
10+
import reflect._
11+
typeOf[Function1[_, _]].classSymbol.get.methods.map(_.name).sorted.mkString("\n")
12+
}
13+
14+
}

tests/run-macros/i6518/Test_2.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
object Test {
3+
4+
def main(args: Array[String]): Unit = {
5+
println(Macros.test())
6+
}
7+
8+
}

0 commit comments

Comments
 (0)