Skip to content

Commit a406225

Browse files
committed
Output parameter names
Partially ports scala/scala#4735
1 parent 5eb3258 commit a406225

File tree

4 files changed

+36
-3
lines changed

4 files changed

+36
-3
lines changed

compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,14 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
335335
emitAssocs(av, assocs, BCodeHelpers.this)(this)
336336
}
337337

338+
/*
339+
* must-single-thread
340+
*/
341+
def emitParamNames(jmethod: asm.MethodVisitor, params: List[Symbol]) =
342+
for param <- params do
343+
var access = asm.Opcodes.ACC_FINAL
344+
jmethod.visitParameter(param.name.mangledString, access)
345+
338346
/*
339347
* must-single-thread
340348
*/

compiler/src/dotty/tools/backend/jvm/BCodeSkelBuilder.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
615615
/*
616616
* must-single-thread
617617
*/
618-
def initJMethod(flags: Int, paramAnnotations: List[List[Annotation]]): Unit = {
618+
def initJMethod(flags: Int, params: List[Symbol]): Unit = {
619619

620620
val jgensig = getGenericSignature(methSymbol, claszSymbol)
621621
val (excs, others) = methSymbol.annotations.partition(_.symbol eq defn.ThrowsAnnot)
@@ -637,7 +637,8 @@ trait BCodeSkelBuilder extends BCodeHelpers {
637637
// TODO param names: (m.params map (p => javaName(p.sym)))
638638

639639
emitAnnotations(mnode, others)
640-
emitParamAnnotations(mnode, paramAnnotations)
640+
emitParamNames(mnode, params)
641+
emitParamAnnotations(mnode, params.map(_.annotations))
641642

642643
} // end of method initJMethod
643644

@@ -749,7 +750,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
749750
.addFlagIf(isNative, asm.Opcodes.ACC_NATIVE) // native methods of objects are generated in mirror classes
750751

751752
// TODO needed? for(ann <- m.symbol.annotations) { ann.symbol.initialize }
752-
initJMethod(flags, params.map(p => p.symbol.annotations))
753+
initJMethod(flags, params.map(_.symbol))
753754

754755

755756
if (!isAbstractMethod && !isNative) {

tests/run/i11486/Old_1.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
case class TestedOld(foo: Int, bar: String, baz: Double):
2+
def target(abc: TestedOld, efg: TestedOld) = ()
3+
def symbolic(`def`: Int, *** : Int, `unary_!`: Int) = ()

tests/run/i11486/Test_2.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import java.lang.reflect.Executable
2+
3+
case class Tested(foo: Int, bar: String, baz: Double):
4+
def target(abc: Tested, efg: Tested) = ()
5+
def symbolic(`def`: Int, *** : Int, `unary_!`: Int) = ()
6+
7+
def run(cls: Class[_]) =
8+
extension(m: Executable) def parameters: List[String] = m.getParameters.toList.map(_.getName)
9+
10+
val ctorParams = cls.getConstructors.head.parameters
11+
assert(ctorParams == List("foo", "bar", "baz"))
12+
13+
val targetParams = cls.getMethods.toList.find(_.getName == "target").get.parameters
14+
assert(targetParams == List("abc", "efg"))
15+
16+
val symbolicParams = cls.getMethods.toList.find(_.getName == "symbolic").get.parameters
17+
assert(symbolicParams == List("def", "$times$times$times", "unary_$bang"))
18+
19+
@main def Test =
20+
run(classOf[TestedOld])
21+
run(classOf[Tested])

0 commit comments

Comments
 (0)