File tree 5 files changed +32
-11
lines changed
compiler/src/dotty/tools/dotc/transform
tests/generic-java-signatures
5 files changed +32
-11
lines changed Original file line number Diff line number Diff line change @@ -838,17 +838,17 @@ object Erasure {
838
838
}
839
839
}
840
840
841
- // TODO: Find how to encode names
842
- def sanitizeName ( name : Name ) : String =
843
- name.toString.replaceAll( """ \! """ , """ \$bang """ )
844
- .replaceAll( """ = """ , """ \$eq """ )
845
- .replaceAll( """ ~ """ , """ \$tilde """ )
846
- .replace( " - " , " $minus " )
847
- .replace( " + " , " $plus " )
848
- .replace( " > " , " $greater " )
849
- .replace( " < " , " $less " )
850
- .replace( " : " , " $colon " )
851
- .replace( " ; " , " $u003B " )
841
+ // This will reject any name that has characters that cannot appear in
842
+ // names on the JVM. Interop with Java is not guaranteed for those, so we
843
+ // dont need to generate signatures for them.
844
+ def sanitizeName ( name : Name ) : String = {
845
+ val nameString = name.mangledString
846
+ if (nameString.forall(c => c == '.' || Character .isJavaIdentifierPart(c))) {
847
+ nameString
848
+ } else {
849
+ throw new UnknownSig
850
+ }
851
+ }
852
852
853
853
// Anything which could conceivably be a module (i.e. isn't known to be
854
854
// a type parameter or similar) must go through here or the signature is
Original file line number Diff line number Diff line change
1
+ class Foo [`![]:;!!` <: java.util.Date ]
2
+
3
+ object Test {
4
+ def main (args : Array [String ]): Unit = {
5
+ val tParams = classOf [Foo [_]].getTypeParameters()
6
+ tParams.foreach { tp =>
7
+ println(tp.getName + " <: " + tp.getBounds.map(_.getTypeName).mkString(" , " ))
8
+ }
9
+ }
10
+ }
Original file line number Diff line number Diff line change
1
+ $bang$bang$bang <: java.util.Date
Original file line number Diff line number Diff line change
1
+ class Foo [`!!!` <: java.util.Date ]
2
+
3
+ object Test {
4
+ def main (args : Array [String ]): Unit = {
5
+ val tParams = classOf [Foo [_]].getTypeParameters()
6
+ tParams.foreach { tp =>
7
+ println(tp.getName + " <: " + tp.getBounds.map(_.getTypeName).mkString(" , " ))
8
+ }
9
+ }
10
+ }
You can’t perform that action at this time.
0 commit comments