Kelvin Chung
08/13/2025, 12:12 AMinterface MyType
value class Wrapper(value: Int) : MyType, WrapperAddOp
interface WrapperAddOp : MyType {
operator fun plus(rhs: Wrapper): Wrapper = // default implementation
}
When I try to run a test (JVM), I get a NoSuchMethodError when I try to invoke the plus method on Wrapper, saying that a mangled name starting with plus on Wrapper doesn't exist. Anyone with any insights on this?Nicolai C.
08/13/2025, 12:52 AMKelvin Chung
08/13/2025, 12:56 AMNicolai C.
08/13/2025, 1:01 AMplus operator function inside the Wrapper value class, or does it only happen when the operator is declared in an interface separate from the value class?Kelvin Chung
08/13/2025, 1:02 AMNoSuchMethodError is being flagged on a mangled plus with Int args, even though my code only defines plus on Wrapper.Kelvin Chung
08/13/2025, 1:03 AMjava.lang.NoSuchMethodError 'int Wrapper.plus-<mangled>(int, int)'Nicolai C.
08/13/2025, 1:05 AMWrapper is basically an opaque type for value: Int, but at runtime it is technically just a normal Int for optimization reasons.Kelvin Chung
08/13/2025, 1:05 AMWrapper wasn't a value class, this would work fine, but the fact that it is creates a design problem for me.Nicolai C.
08/13/2025, 1:06 AMKelvin Chung
08/13/2025, 1:07 AMNicolai C.
08/13/2025, 1:13 AMWrapper works. Are you reusing the default implementation of WrapperAddOp in Wrapper or did you override it with a different implementation?Kelvin Chung
08/13/2025, 1:15 AMWrapperAddOp in Wrapper, no overridesNicolai C.
08/13/2025, 1:16 AMKelvin Chung
08/13/2025, 1:21 AMWrapper inherits the body of WrapperAddOp.plusKelvin Chung
08/13/2025, 1:22 AMvalue class Wrapper(value: Int) : MyType, WrapperAddOp {
override fun plus(rhs: Wrapper): Wrapper = super.plus(rhs)
}
Seems to do the trickKelvin Chung
08/13/2025, 1:24 AMNicolai C.
08/13/2025, 1:24 AMKelvin Chung
08/13/2025, 1:26 AMNicolai C.
08/13/2025, 1:30 AMKelvin Chung
08/13/2025, 2:06 AMNicolai C.
08/13/2025, 2:12 AMKelvin Chung
08/13/2025, 2:27 AMkotlin {
jvm {
compilerOptions {
jvmDefault.set(JvmDefaultMode.NO_COMPATIBILITY)
}
}
}
The issues seem to disappear entirely, so it must be a Kotlin 2.2.0 thing. To what extent this can be considered a regression is probably beyond my understanding.Nicolai C.
08/13/2025, 2:41 AM