Skip to content

Commit 6d22269

Browse files
committed
Don't generate signatures for backticked-names
1 parent c94748f commit 6d22269

File tree

5 files changed

+32
-11
lines changed

5 files changed

+32
-11
lines changed

compiler/src/dotty/tools/dotc/transform/Erasure.scala

+11-11
Original file line numberDiff line numberDiff line change
@@ -838,17 +838,17 @@ object Erasure {
838838
}
839839
}
840840

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+
}
852852

853853
// Anything which could conceivably be a module (i.e. isn't known to be
854854
// a type parameter or similar) must go through here or the signature is

tests/generic-java-signatures/invalidNames.check

Whitespace-only changes.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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 numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
$bang$bang$bang <: java.util.Date
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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+
}

0 commit comments

Comments
 (0)