Skip to content

Commit 9f39e35

Browse files
committed
Addapt GenericSignatures to handle unused parameters
1 parent 5d803ba commit 9f39e35

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-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,8 +239,13 @@ object GenericSignatures {
239239
methodResultSig(restpe)
240240

241241
case mtpe: MethodType =>
242-
// phantom method parameters do not make it to the bytecode.
243-
val params = mtpe.paramInfoss.flatten.filterNot(_.isPhantom)
242+
// unused method parameters do not make it to the bytecode.
243+
def effectiveParamInfoss(t: Type)(implicit ctx: Context): List[List[Type]] = t match {
244+
case t: MethodType if t.isUnusedMethod => effectiveParamInfoss(t.resType)
245+
case t: MethodType => t.paramInfos.filterNot(_.isPhantom) :: effectiveParamInfoss(t.resType)
246+
case _ => Nil
247+
}
248+
val params = effectiveParamInfoss(mtpe).flatten
244249
val restpe = mtpe.finalResultType
245250
builder.append('(')
246251
// TODO: Update once we support varargs
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
public <U> int MyUnused$.f1()
2+
U <: java.lang.Object
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
object MyUnused {
2+
def f1[U](unused a: Int): Int = 0
3+
}
4+
5+
object Test {
6+
def main(args: Array[String]): Unit = {
7+
val f1 = MyUnused.getClass.getMethods.find(_.getName.endsWith("f1")).get
8+
val tParams = f1.getTypeParameters
9+
println(f1.toGenericString)
10+
tParams.foreach { tp =>
11+
println(tp.getName + " <: " + tp.getBounds.map(_.getTypeName).mkString(", "))
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)