Repository navigation
docs(emitters): encode every enum member as its JSON kind - #1334
Open
OmarAlJarrah wants to merge 6 commits into
Open
OmarAlJarrah wants to merge 6 commits into
OmarAlJarrah wants to merge 6 commits into
Conversation
An enum whose value type has no Go constant form, a date, a uuid or a decimal, had no Go lowering, and the type table built an enum value by decoding its wire form, which no constant can be. Kotlin's enum class writes every member as its @SerialName string, so a boolean or numeric enum went out as a string its schema does not admit. A member is now written as the JSON kind its value type has, and decoded by comparing as JSON compares values, numbers by value. Go declares an enum over its value type's row, and over the wire text where the row has no constant, the codec writing the value type's JSON kind and a Value method giving the row's type. Kotlin generates a KSerializer for every enum that is not a string enum, and an entry of a mapped type holds its value as that type. T-36 pins every value type on every target.
…o docs/emitters-enum-value-types
…o docs/emitters-enum-value-types
…o docs/emitters-enum-value-types
…o docs/emitters-enum-value-types
…o docs/emitters-enum-value-types
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
An enum whose value type has no Go constant form had no Go lowering. Under
docs/emitters/targets/go/types.mda closed enum was typed constants, and Go declares constants of boolean, numeric and string types alone.docs/emitters/contract/type-table.mdbuilt an enum value by decoding its wire form through the row's codec, which no constant can be. Sweeping the mechanism ("a target's enum form cannot hold every value type") found a second, wider site the issue ruled out. Kotlin'senum classwith@SerialNamemembers writes every member as a string, so aboolor numeric enum goes out as a string its schema does not admit. On the golden spec that is 1,069bool, 35integerand 348numberenums (spec @319dc756, morphic @b206dc99), so the Kotlin half is on the golden spec even though the Go half is not.docs/emitters/refine/enums.md#a-member-on-the-wire). A member's wire form is itsWireName, else itsValueas the JSON kind of the enum'sValueType. Every target decodes by comparing as JSON compares values: numbers by value, so0.1and0.10are one member, and everything else by text whateverformatsays, which is what theenumkeyword compares.date,time,datetime,datetime_offset,duration,uuid,bytes,decimal, and an exactly mappedintegerornumber), it is a namedstringover the member's wire text instead. Its codec writes the value type's JSON kind, so a decimal stays a JSON number, and aValue()method decodes the text through the row's codec. That reconciles the type table, which now says so. This is the issue's first alternative, with the number case it left open settled. The second, package-level variables built through the codec, lost for the reasons the issue gave: avarcan be assigned, and==is wrong fortime.Timeand absent for a decimal overmath/big. Both are recorded in the document.stringenum keeps@SerialName. Every other closed enum gets a generatedKSerializerwriting its JSON kind, and an entry of a mapped value type holdsval value: LocalDateand the like, built through the row's codec.Out of scope, as the issue says: which primitive
ValueTypeholds (#1191 settled it; #1325 adds localtimeanddatetimeforms, which the rule's list of rows with no Go constant already covers).Closes #1202
Test plan
Valuesignature, passesgo vet.bool1,069,integer35,number348,string6,862.Stacked on #1332 (then #1331 and #1329), since #1332 rewrote the same enum paragraphs. Merge in order. After each lands, "Update branch" on the next is a merge of
mainthat conflicts nowhere.