Skip to content

Commit f6b0ee3

Browse files
committed
Fix generic signatures of generic methods
We ignored the case where a `MethodType` had another `MethodType` as result type. This commit fixes the issue by collecting the parameters of the result type if it is a `MethodType`, recursively. Fixes #3411
1 parent 6398448 commit f6b0ee3

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,14 @@ object GenericSignatures {
239239
methodResultSig(restpe)
240240

241241
case mtpe: MethodType =>
242+
def allParamTypes(mtpe: MethodType): List[Type] =
243+
mtpe.resultType match {
244+
case restpe: MethodType => mtpe.paramInfos ::: allParamTypes(restpe)
245+
case _ => mtpe.paramInfos
246+
}
242247
// phantom method parameters do not make it to the bytecode.
243-
val params = mtpe.paramInfos.filterNot(_.isPhantom)
244-
val restpe = mtpe.resultType
248+
val params = allParamTypes(mtpe).filterNot(_.isPhantom)
249+
val restpe = mtpe.finalResultType
245250
builder.append('(')
246251
// TODO: Update once we support varargs
247252
params.foreach { tp =>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
public <U> float Foo$.foo(int,java.lang.String,long,boolean,U,java.lang.String,java.lang.Object)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
object Foo {
2+
def foo[U](i: Int, s: String, x: Long)(c: Boolean, a: U, d: String)(e: Object): Float = 0.0f
3+
}
4+
5+
object Test {
6+
def main(args: Array[String]): Unit = {
7+
val f1 = Foo.getClass.getMethods.find(_.getName.endsWith("foo")).get
8+
println(f1.toGenericString)
9+
}
10+
}

0 commit comments

Comments
 (0)