Repository navigation
Conversation
`accessors-enum-union.schema` has the same enum twice, as a definition with `qt-accessors` and inline in a nullable union, which is what the TypeScript input makes of `f: E | null` for a string enum. A unit test covers two definitions of the same enum with `qt-enum-values`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`AccessorNamesTypeAttributeKind` and `EnumValuesTypeAttributeKind` had no `combine`, so two types with accessor names (or enum values) that turned out to be the same type stopped with "Internal error: Cannot combine type attribute accessorNames." The TypeScript input gives a string enum's definition its member names as `qt-accessors`, so string enums in unions (`E | null`, `E[] | F`, an optional `E` in Python) and two enums with the same values failed, as did JSON Schema definitions of the same enum with `qt-accessors`. Accessor names now keep the entries every copy agrees on, and drop a name the copies disagree on, so it falls back to its default. Enum values combine only when every copy is the same; any other combination fails as before, because dropping a value could give two cases the same value. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
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.
Description
AccessorNamesTypeAttributeKindandEnumValuesTypeAttributeKindget acombine. Before this, both used the base class's, which panics withCannot combine type attribute ….attributes/AccessorNames.ts): the result keeps everyentry the combined copies agree on, and drops a name for which they
have different entries, so that name falls back to its default name.
Names that only one copy gives are kept.
attributes/EnumValues.ts): copies that are all the sameare combined. Any other combination fails as before, with the same
message.
A test commit adds
test/inputs/schema/accessors-enum-union.schema. Ithas the same enum twice, once as a definition with
qt-accessorsand onceinline in a nullable union, which is what the TypeScript input makes of
f: E | nullfor a string enum. It comes with two samples and oneexpected failure (
"f": "c"). The commit also adds a unit test,test/unit/enum-values-combine.test.ts: two definitions with identicalqt-enum-valuescombine (_A = 0,,_B = 1,in C), and two that differstill fail with
Cannot combine type attribute enumValues.Related Issue
Fixes #3551
Motivation and Context
The TypeScript input gives each string enum's definition its member names
as
qt-accessors. When the same enum also appears in a union(
E | null,E[] | F, an optionalEin Python), or two enums have thesame cases, the types become one and their attributes are combined, and
quicktype stopped with
Internal error: Cannot combine type attribute accessorNames.JSON Schema definitions of the same enum with
qt-accessorsorqt-enum-valuesfailed the same way.Why these semantics:
so its member names are kept.
f: E | nullnames the cases asf: Edoes.
more right than the other. Dropping the name gives the result the
string-literal alias form (
type E = "a" | "b") gives, and the resultdoes not depend on the order in which types are combined. Keeping the
first or the last entry would depend on it.
the enum means, and dropping one can give two cases the same value.
With copies
{"a": "0", "b": "1"}and{"a": "1", "b": "1"}, droppingagives CF_A = 1, F_B = 1(the first case defaults to 1), and theduplicate
caselabels do not compile.Previous Behaviour / Output
with
e.ts:New Behaviour / Output
The code is generated. For these four declarations, the output is
byte-for-byte the same as for the same declarations written with string-literal
aliases, in C#, Python, Go and TypeScript:
f: E | nullf: E[] | Fe: E; f: F, whereFhas the same cases asEf?: E; g?: EFor the JSON Schema example with two definitions whose
qt-accessorsare{a: Alpha, b: Beta}and{a: Alpha, b: Other}, the C# enum is{ Alpha, B }. Two definitions with identicalqt-enum-valuesnow work.Definitions whose
qt-enum-valuesdiffer still fail withCannot combine type attribute enumValues.No output of the repository's existing inputs changes, since combining
these attributes always failed before.
How Has This Been Tested?
Environment: macOS 26.6 (arm64), Node 24.16.0, Python 3.12.16 with
mypy 2.4.1, OpenJDK 21.0.11 with Maven 3.10.0, Ruby 4.0.6, Apple clang 21
(C, C++, Objective-C), Swift, Rust (cargo) and Dart.
On this branch:
npm ci,npm run build,npm run lint(passes),npm run test:unit(55 files, 243 tests pass).
QUICKTEST=true FIXTURE=schema-typescript,schema-javascript,schema-python,schema-cjson,schema-ruby,schema-java npm run test:fixtures -- test/inputs/schema/accessors-enum-union.schema:all 6 pass.
schema-swift,schema-rust,schema-dart,schema-typescript-zod,schema-typescript-effect-schema,schema-flow,schema-javascript-prop-types,schema-java-datetime-legacy,schema-objective-candschema-cplusplus: all 10 pass.--langexceptobjc, which fails withInternal error: Cannot repeat a string a negative number of times.The string-literal alias form fails the same way on master, so that is
a separate problem.
With only the test commit (the fix not applied):
schema-typescript(and the others) fail onaccessors-enum-union.schemawith
Internal error: Cannot combine type attribute accessorNames.Not run here, because the toolchains are not installed: C#, Go, Kotlin,
Scala, Elm, PHP, Elixir, Haskell, Crystal and Pike.
Screenshots (if appropriate):
n/a
Written by Claude (an AI assistant made by Anthropic) and posted on behalf of the account owner (EloB). The reproduction, fix and tests were checked by running them as described above.
🤖 Generated with Claude Code