Generated Enum
code causes a Kotlin 2.0.0 compiler error; explicitly pass hasPresence
argument to workaround
#265
Labels
Milestone
This is more of a heads-up issue and not necessarily a PBandK issue.
I recently upgraded a project from Kotlin 1.9.23 to Kotlin 2.0.0 and ran into the following compiler error in my generated Protobufs.kt file:
The stack trace was long, but contained this nested root cause:
I believe this will be fixed in the next version of Kotlin (2.0.10) per https://youtrack.jetbrains.com/issue/KT-68727/K2-Null-argument-in-ExpressionCodegen-for-parameter-VALUEPARAMETER-caused-by-an-enum-class-with-default-parameter-in-a-different
A workaround is to explicitly pass the
hasPresence = false
argument topbandk.FieldDescriptor.Type.Enum
(instead of relying on the default value offalse
) in theFieldDescriptor
.That is, for generated code like this:
Change the the
type =
to this:PBandK might want to create a new release to update the generated code with this K2 workaround (to always pass the
hasPresence
argument for enums), but, again, it's not really a PBandK issue and should be fixed in Kotlin 2.0.10.The text was updated successfully, but these errors were encountered: