From 24601e44561cc9999ce9a8a350d4c43b7003133c Mon Sep 17 00:00:00 2001 From: Martin Duhem Date: Tue, 31 Oct 2017 16:29:21 +0100 Subject: [PATCH] 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 --- .../dotty/tools/dotc/transform/GenericSignatures.scala | 4 ++-- tests/generic-java-signatures/i3411.check | 1 + tests/generic-java-signatures/i3411.scala | 10 ++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 tests/generic-java-signatures/i3411.check create mode 100644 tests/generic-java-signatures/i3411.scala diff --git a/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala b/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala index d50f2e11ab38..e95815cc0e5b 100644 --- a/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala +++ b/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala @@ -240,8 +240,8 @@ object GenericSignatures { case mtpe: MethodType => // phantom method parameters do not make it to the bytecode. - val params = mtpe.paramInfos.filterNot(_.isPhantom) - val restpe = mtpe.resultType + val params = mtpe.paramInfoss.flatten.filterNot(_.isPhantom) + val restpe = mtpe.finalResultType builder.append('(') // TODO: Update once we support varargs params.foreach { tp => diff --git a/tests/generic-java-signatures/i3411.check b/tests/generic-java-signatures/i3411.check new file mode 100644 index 000000000000..55dcdf6e8042 --- /dev/null +++ b/tests/generic-java-signatures/i3411.check @@ -0,0 +1 @@ +public float Foo$.foo(int,java.lang.String,long,boolean,U,java.lang.String,java.lang.Object) diff --git a/tests/generic-java-signatures/i3411.scala b/tests/generic-java-signatures/i3411.scala new file mode 100644 index 000000000000..b8c4b9f47a98 --- /dev/null +++ b/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) + } +}