From bd4b6dddc62371bb685a7e2eefc9ec49610253e0 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 31 Oct 2017 14:55:50 +0100 Subject: [PATCH] Addapt GenericSignatures to handle `unused` parameters --- .../tools/dotc/transform/GenericSignatures.scala | 4 ++-- tests/generic-java-signatures/unused.check | 2 ++ tests/generic-java-signatures/unused.scala | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 tests/generic-java-signatures/unused.check create mode 100644 tests/generic-java-signatures/unused.scala diff --git a/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala b/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala index d50f2e11ab38..04b32d8c076e 100644 --- a/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala +++ b/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala @@ -239,8 +239,8 @@ object GenericSignatures { methodResultSig(restpe) case mtpe: MethodType => - // phantom method parameters do not make it to the bytecode. - val params = mtpe.paramInfos.filterNot(_.isPhantom) + // unused method parameters do not make it to the bytecode. + val params = if (mtpe.isUnusedMethod) Nil else mtpe.paramInfos.filterNot(_.isPhantom) val restpe = mtpe.resultType builder.append('(') // TODO: Update once we support varargs diff --git a/tests/generic-java-signatures/unused.check b/tests/generic-java-signatures/unused.check new file mode 100644 index 000000000000..4cf5a4d8612c --- /dev/null +++ b/tests/generic-java-signatures/unused.check @@ -0,0 +1,2 @@ +public int MyUnused$.f1() +U <: java.lang.Object diff --git a/tests/generic-java-signatures/unused.scala b/tests/generic-java-signatures/unused.scala new file mode 100644 index 000000000000..4ccf930a8500 --- /dev/null +++ b/tests/generic-java-signatures/unused.scala @@ -0,0 +1,14 @@ +object MyUnused { + def f1[U](unused a: Int): Int = 0 +} + +object Test { + def main(args: Array[String]): Unit = { + val f1 = MyUnused.getClass.getMethods.find(_.getName.endsWith("f1")).get + val tParams = f1.getTypeParameters + println(f1.toGenericString) + tParams.foreach { tp => + println(tp.getName + " <: " + tp.getBounds.map(_.getTypeName).mkString(", ")) + } + } +}