arrow-kt / arrow

Λrrow - Functional companion to Kotlin's Standard Library
http://arrow-kt.io
Other
6.19k stars 448 forks source link

["BUG"][Arrow Optics] Unresolved reference when a property have same name with package name #2909

Closed risalfajar closed 1 year ago

risalfajar commented 1 year ago

What version are you currently using? 1.1.5

I have this class (notice id parameter and the package name):

package id.co.appname.features.main.transaction.data

import arrow.optics.optics

@optics
data class TransactedItem(
    val id: String = "", // package name also contains "id"
    val code: String = "",
    val name: String = "",
    val location: String = "",
    val quantity: Int = 0,
    val unit: String = ""
) {
    companion object
}

This is what happens: image

I believe there's a clash between id property from TransactedItem with id from package name. For now removing or renaming the id property works, maybe changing package name could work too, but it's impossible for my project.

Is there any solution? Ignoring id property from optics could also work since I don't need it to change, but I don't know how.

ibado commented 1 year ago

Hello :wave: I've created a PR fixing this one. LMK what you think :slightly_smiling_face:

risalfajar commented 6 months ago

Hello @ibado, thanks for the fix last year.

But I just found out that the error still exists for ISO optics target:

public inline val id.co.company.app.features.main.transaction.tug.`data`.TransactedItem.Companion.iso: arrow.optics.Iso<id.co.company.app.features.main.transaction.tug.`data`.TransactedItem, arrow.core.Tuple7<kotlin.String, kotlin.String, kotlin.String, kotlin.String, kotlin.Int, kotlin.String, id.co.company.app.features.main.transaction.tug.`data`.ReturnDetails>> inline get() = arrow.optics.Iso(
  get = { transactedItem: id.co.company.app.features.main.transaction.tug.`data`.TransactedItem -> arrow.core.Tuple7(transactedItem.`id`, transactedItem.`code`, transactedItem.`name`, transactedItem.`unit`, transactedItem.`quantity`, transactedItem.`location`, transactedItem.`returnDetails`) },
  reverseGet = { tuple: arrow.core.Tuple7<kotlin.String, kotlin.String, kotlin.String, kotlin.String, kotlin.Int, kotlin.String, id.co.company.app.features.main.transaction.tug.`data`.ReturnDetails> -> id.co.company.app.features.main.transaction.tug.`data`.TransactedItem(tuple.first, tuple.second, tuple.third, tuple.fourth, tuple.fifth, tuple.sixth, tuple.seventh) }
)

It only happens on line 3 after the arrow ->. Should this issue be reopened?