Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

["BUG"] Optics and typealias usage in the same file fails with "Duplicate JVM class name" #2803

Closed
mmirboboev opened this issue Aug 22, 2022 · 1 comment · Fixed by #2850
Closed

Comments

@mmirboboev
Copy link

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 🙏🏼

@thejeff77
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants