Skip to content

Commit

Permalink
Fix generic signatures of generic methods
Browse files Browse the repository at this point in the history
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 scala#3411
  • Loading branch information
Duhemm committed Oct 31, 2017
1 parent 6398448 commit f6b0ee3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Expand Up @@ -239,9 +239,14 @@ object GenericSignatures {
methodResultSig(restpe)

case mtpe: MethodType =>
def allParamTypes(mtpe: MethodType): List[Type] =
mtpe.resultType match {
case restpe: MethodType => mtpe.paramInfos ::: allParamTypes(restpe)
case _ => mtpe.paramInfos
}
// phantom method parameters do not make it to the bytecode.
val params = mtpe.paramInfos.filterNot(_.isPhantom)
val restpe = mtpe.resultType
val params = allParamTypes(mtpe).filterNot(_.isPhantom)
val restpe = mtpe.finalResultType
builder.append('(')
// TODO: Update once we support varargs
params.foreach { tp =>
Expand Down
1 change: 1 addition & 0 deletions tests/generic-java-signatures/i3411.check
@@ -0,0 +1 @@
public <U> float Foo$.foo(int,java.lang.String,long,boolean,U,java.lang.String,java.lang.Object)
10 changes: 10 additions & 0 deletions tests/generic-java-signatures/i3411.scala
@@ -0,0 +1,10 @@
object Foo {
def foo[U](i: Int, s: String, x: Long)(c: Boolean, a: U, d: String)(e: Object): Float = 0.0f
}

object Test {
def main(args: Array[String]): Unit = {
val f1 = Foo.getClass.getMethods.find(_.getName.endsWith("foo")).get
println(f1.toGenericString)
}
}

0 comments on commit f6b0ee3

Please sign in to comment.