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
Do not use 'header' as a enum value name as it breaks the Kotlin compiler #4086
Conversation
✅ Deploy Preview for apollo-android-docs canceled.
|
@@ -13,7 +13,8 @@ private val JAVA_RESERVED_WORDS = arrayOf( | |||
|
|||
// Reference: | |||
// https://kotlinlang.org/docs/enum-classes.html#working-with-enum-constants:~:text=properties%20for%20obtaining%20its%20name%20and%20position | |||
private val KOTLIN_RESERVED_ENUM_VALUE_NAMES = arrayOf("name", "ordinal") | |||
// "header" and "impl" are added to this list because of https://youtrack.jetbrains.com/issue/KT-52315 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😱
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR to handle this at the KotlinPoet level: square/kotlinpoet#1248
Updated this PR with a better fix that escapes with backticks. If this gets fixed in the Kotlin compiler, no change will be needed on the caller side |
fun String.escapeKotlinReservedEnumValueNames() : String { | ||
return when { | ||
// https://kotlinlang.org/docs/enum-classes.html#working-with-enum-constants:~:text=properties%20for%20obtaining%20its%20name%20and%20position | ||
this in arrayOf("name", "ordinal") -> "${this}_" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you remember why we don't use backticks for these two as well? (we wouldn't want to change this now as it would be breaking, but I'm curious if we simply didn't think of it or a good reason).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's different. One is an actual language limitation (name, ordinal). I think because there's a nameclash somewhere. The other is most likely a compiler bug (header, impl).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if you want to
"(?:name|ordinal)_*".toRegex().matches(this)
to prevent collisions if a schema defines both name
and name_
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent point, much better 👍
See https://youtrack.jetbrains.com/issue/KT-52315
Thanks @ephemient for catching this!