I see plenty of mentions that `fun `backtick in fu...
# multiplatform
h
I see plenty of mentions that `fun `backtick in function names`` is not allowed in kotlin-js, but I'm trying to use them in some tests in a KMM project, and it's also failing for iOS while they work fine for Android. I'm pretty sure the answer is going to be the same, that it's not supported. But could someone confirm that for me, or point me to where I can confirm it myself? To be clear, the error I'm getting is not explicitly for the backticks, but rather the spaces and commas.
j
Note that they (spaces) only work on Android API 30+ which is a very limited subset
The backticks are part of the language and just tell the Kotlin compiler to take all of the characters until the next backtick as the name. It's perfectly valid to use backticks for like
Copy code
fun `hi`() { .. }
and have it work on every platform because the backticks don't actually do anything.
h
Thanks Jake. So it's up to whether the kotlin compiler for a specific platform can support spaces/punctation?
j
For Android, the Kotlin compiler always allows it. But when you go to build the application/test APK it's D8 which will fail (unless your minSdk is 30+). For JS the check is in the Kotlin compiler–it simply won't compile. I'm not sure what Kotlin/Native does, but I suspect the Kotlin compiler does no enforcement and any limitations will be from the final LLVM compilation to the actual native target.
e
Kotlin/JVM disallows the following characters
.;[]/<>:\
as those are considered special by the JVM. Android has stricter limits than the JVM, as Jake mentions, but Kotlin doesn't enforce that
Kotlin/JS sticks to ES5 identifiers, so sequences of letters, numbers, or specific special characters such as
$
and
_
, as long as it doesn't start with a digit
Kotlin/Native actually applies its own check, rejecting
.;,()[]{}/<>:\$&~*?#|§^@
- I'm not sure why on some of them, because native linkers ought to be OK with those as far as I know… but
;,()[]{}<>&~
are used by Kotlin's own name mangler
g
Would it be safe for Kotlin to replace for example the spaces to a convenient char like
-
when running on a platform that doesn't support spaces? I mean I care about tests running and having a clean test code, but for me I don't mind if the test reports are a bit different depending of the platform.
j
This option was rejected by D8 because it breaks things like stack traces and test methods association
e
in principle, if R8 mangles the names first, D8 won't see the original with "bad" characters
j
Yes, but they're also not separate tools so it doesn't quite work like that. R8 can be thought of as D8 but with an extra step in the middle that rewrites names. The part that fails is the part that parses class files before the obfuscation step or the lowering to dalvik step happens.