diff --git a/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala b/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala index 513e08ccf258..caf68ce8d407 100644 --- a/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala +++ b/compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala @@ -6,7 +6,7 @@ import core.Annotations.Annotation import core.Contexts.Context import core.Definitions import core.Flags._ -import core.Names.Name +import core.Names.{DerivedName, Name, SimpleName, TypeName} import core.Symbols._ import core.TypeApplications.TypeParamInfo import core.TypeErasure.erasure @@ -17,6 +17,8 @@ import SymUtils._ import TypeUtils._ import java.lang.StringBuilder +import scala.annotation.tailrec + /** Helper object to generate generic java signatures, as defined in * the Java Virtual Machine Specification, ยง4.3.4 */ @@ -161,7 +163,7 @@ object GenericSignatures { // TODO revisit this. Does it align with javac for code that can be expressed in both languages? val delimiter = if (builder.charAt(builder.length() - 1) == '>') '.' else '$' - builder.append(delimiter).append(sanitizeName(sym.name.asSimpleName)) + builder.append(delimiter).append(sanitizeName(sym.name)) } else fullNameInSig(sym) } diff --git a/tests/generic-java-signatures/derivedNames.check b/tests/generic-java-signatures/derivedNames.check new file mode 100644 index 000000000000..ddcd95bfca29 --- /dev/null +++ b/tests/generic-java-signatures/derivedNames.check @@ -0,0 +1 @@ +Test$Foo$A$B$> diff --git a/tests/generic-java-signatures/derivedNames.scala b/tests/generic-java-signatures/derivedNames.scala new file mode 100644 index 000000000000..e2bcbe0eecc0 --- /dev/null +++ b/tests/generic-java-signatures/derivedNames.scala @@ -0,0 +1,15 @@ +object Test { + def main(args: Array[String]): Unit = { + val objectB = classOf[Foo[Any]].getClasses + val returnType = objectB(1).getDeclaredMethod("m").getGenericReturnType + println(returnType) + } + class Foo[T1] { + class A[T2] + + object B { + def m: A[B.type] = ??? + } + } +} +