arrow
arrow copied to clipboard
["BUG"] Optics and typealias usage in the same file fails with "Duplicate JVM class name"
Hello arrow ⏫ team,
Recently I was playing around and trying to integrate arrow-optics into one of our kotlin projects with spring-boot, but stumbled upon an issue.
When declaring a typealias in the same file where I have @optics annotation, build of the gradle application fails with Duplicated JVM name error.
Below is the example:
package com.example.arrow.optics
import arrow.optics.optics
import java.util.UUID
typealias OrderId = UUID
@optics
data class Order(val id: OrderId) {
companion object
}
Error message:
Task :compileKotlin FAILED
e: /Users/mirboboev/playground/arrow.optics/build/generated/ksp/main/kotlin/com/example/arrow/optics/arrow/optics/Order.kt: (1, 1): Duplicate JVM class name 'com/example/arrow/optics/arrow/optics/OrderKt' generated from: OrderKt, OrderKt
e: /Users/mirboboev/playground/arrow.optics/src/main/kotlin/com/example/arrow/optics/arrow/optics/Order.kt: (1, 1): Duplicate JVM class name 'com/example/arrow/optics/arrow/optics/OrderKt' generated from: OrderKt, OrderKt
Possible solutions is to explicitly specify java class name in the beginning of the file like in the example below:
@file:JvmName("OrderJvm")
Thanks 🙏🏼
This gave me the tip I needed to fix a very similar issue! Thank you!
You also get this if you have extension functions for the sealed class - esp in the same file.
Eg:
@optics
data class Order(val id: OrderId) {
companion object
}
Order.toSomeObject() = SomeObject.from(this)
Obviously you can put it in the class instead of using an extension function, but it might help to have this context when fixing this.