I have a weird case with the following This code: ...
# compiler
k
I have a weird case with the following This code:
Copy code
sealed class Fragment {
    abstract val name: String?
}
data class Gauge(
    @field:JvmField
    override val name: String? = null,
    @field:JvmField
    val maxValue: Int
) : Fragment()
compiles fine w/o any warning (jvm target ofc) but fails in runtime
Copy code
val foo: Fragment = Gauge("name", 7)
foo.name
which makes some sense because by just looking at Fragment calling
getName
seems safe But what is weirder
Copy code
Gauge("name", 7).toString() // or other generated data class method like equals/hashcode/...
also tries to call getName instead of just using the field... (which seems like a bug on its own) Ideally the compiler could generate a synthetic
getName
for the data class in this case to fulfil both contracts otherwise shouldn't this at least be a error(/warning maybe?) from the compiler?