fix(haskell): render any-type as Aeson Value instead of Maybe Text#2994
Merged
Conversation
…2005) Co-Authored-By: gpt-5.6-sol via pi <noreply@openai.com>
# Conflicts: # test/languages.ts
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.
Bug
The Haskell renderer mapped quicktype's "any" type to
Maybe Text, whichonly decodes JSON strings or
null. Any schema resolving to any-type —including a bare empty schema
{}and nested cases likeadditionalProperties: true— generated Haskell code that fails to decodevalid JSON values that aren't strings or null (numbers, booleans, objects,
arrays).
Repro:
Before:
After:
Root cause
HaskellRenderer.ts'shaskellTypemappedanyTypetoMaybe Textinstead of a type that can hold arbitrary JSON. TypeScript emits
any,Dart emits
dynamic, and Elm already handles this correctly by emittingJdec.value(Elm's arbitrary-JSON type). Aeson'sValueis the Haskellequivalent — it has identity
ToJSON/FromJSONinstances and canrepresent any JSON value.
Fix
In
packages/quicktype-core/src/language/Haskell/HaskellRenderer.ts,anyTypenow renders asValue(fromData.Aeson, already imported)instead of
Maybe Text.Test coverage
any.schemaJSON Schema fixture for the Haskelltarget (previously in
skipSchema).test/inputs/schema/any.schemato add anadditionalProperties: trueproperty alongside the existing bare{}property.any.N.jsonsamples to include non-string any-typed values(numbers, objects, arrays, booleans, null) that would fail to round-trip
under the old
Maybe Textmapping.Verification
npm run buildpasses.type Empty = Maybe Texttotype Empty = Value.any.schemafixture would fail on the unfixedrenderer (a
Maybe Textfield cannot decode a JSON number/object/array)and generates correct-looking Aeson-based code after the fix.
test (
QUICKTEST=true FIXTURE=schema-haskell script/test) could not becompiled and run locally; CI will validate the generated Haskell actually
compiles and round-trips correctly.
Fixes #2005
🤖 Generated with Claude Code