https://kotlinlang.org logo
#compiler
Title
# compiler
m

Mikhail

07/21/2022, 7:53 PM
Is there any way to disable mangling for functions that consume inline classes? Spring Data cant deal with this.
e

ephemient

07/21/2022, 7:57 PM
https://kotlinlang.org/docs/inline-classes.html#calling-from-java-code but it's not really usable with inheritance (without further hacks), so hopefully that's not the case you're in
m

Mikhail

07/21/2022, 8:00 PM
Oh, I forgot about
@JvmName
, TYSM!
Well, I get
'@JvmName' annotation is not applicable to this declaration
And here is my code:
Copy code
@Repository
interface WebhookRepository : JpaRepository<Webhook, WebhookId> {

    @JvmName("findWebhookByName")
    fun findWebhookByName(name: WebhookId): Optional<Webhook>
}
e

ephemient

07/21/2022, 8:03 PM
yes, because of the issue I linked
there isn't a good solution
m

Mikhail

07/21/2022, 8:04 PM
Is there any?
e

ephemient

07/21/2022, 8:05 PM
you can
@Suppress
the error away, but you have to manually use the correct
@JvmName
on every overload (otherwise you get missing methods at runtime… this is why it's a compiler error)
m

Mikhail

07/21/2022, 8:05 PM
I'm not implementing this interface, Spring does. I'll try what you suggested
e

ephemient

07/21/2022, 8:06 PM
if it's only implemented from the Java side then
Copy code
@Repository
interface WebhookRepository : JpaRepository<Webhook, WebhookId> {
    @Suppress("INAPPLICABLE_JVM_NAME")
    @JvmName("findWebhookByName")
    fun findWebhookByName(name: WebhookId): Optional<Webhook>
}
should be sufficient
if it's ever implemented in Kotlin you must remember to manually add
@Suppress("INAPPLICABLE_JVM_NAME") @JvmName("findWebhookByName")
to the override
m

Mikhail

07/21/2022, 8:11 PM
It's implemented via codegen 🧌 by Spring Data
Well, it worked perfectly. Thank you again. I'll open an issue about it, maybe Spring Data team find a way to be tolerant to Kotlin's function mangling while method name parsing
e

ephemient

07/21/2022, 8:13 PM
if they're using APT for codegen then there's not much they can do about it - there's no way to represent the mangled names in the Java model
if they're doing it with proxies at runtime or similar, then yeah it could be doable
m

Mikhail

07/21/2022, 8:14 PM
Yeah, they use cglib
94 Views