Is @JvmName supposed to allow characters from this...
# compiler
n
Is @JvmName supposed to allow characters from this list to work within identifiers when with back ticks? Kotlin/JVM (any declaration publicity) ~ ( [\r\n] | '`' | '.' | ';' | ':' | '\' | '/' | '[' | ']' | '<' | '>' ) https://kotlinlang.org/docs/reference/grammar.html#Identifier
n
To clarify, I meant shouldn't I be able to use @JvmName in the following way to avoid using these restricted characters in the generated class even if they are used in Kotlin?
Copy code
@JvmName("foo") // <--- Guarantees the generated class has no illegal function name?
fun `<` () {}
b
It may work, but I’m not sure it does now 🙂
why do you need that?
n
Sadly I get an error. Would love to see this work, since it would help in cases where these characters improve readability, despite needing to be escaped with back ticks. What's the intended behavior?
b
I’d expect it works in this combination, so feel free file an issue with explanation why do you need it.
But I still don’t feel it’s critical.
y
As with a lot of errors in Kotlin, you can actually suppress it and get the behavior you want like this:
Copy code
@Suppress("INVALID_CHARACTERS")
@JvmName("foo") // <--- Guarantees the generated class has no illegal function name?
fun `<` () {}
But yes I agree that @JvmName should automatically stop that error from appearing
n
Suppressing the error allows compile to succeed. But I get an Unresolved reference error whenever referring to it on the JVM (say in code within jvmMain/Test); despite the @JvmName annotation.
Copy code
compiles if not called
----------------------

class Bar {
    @Suppress("INVALID_CHARACTERS")
    @JvmName("foo")
    infix fun `<` (value: Int) {}
}
Copy code
Bar() `<` 10 <------ Unresolved reference: `<` (when called within JVM source set)
y
Is the
Bar
class in a common sourceset?
n
yep