Repository navigation
Conversation
A class could refer to a union class that was declared after it: in `recursive-union-flattening.schema`, `class X` has `Types.Array(Types.Instance(XElement))`, and loading the file failed with `uninitialized constant X::XElement (NameError)`. Only classes were forward-declared, but a union that needs a name is emitted as a `Dry::Struct` class too, so it can be forward-declared the same way. 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
RubyRenderer.canBeForwardDeclarednow accepts a union that needs a name(
unionNeedsName) as well as a class. Such a union is emitted as aDry::Structclass (emitUnion), so it can be forward-declared the sameway:
class XElement < Dry::Struct; end.Related Issue
Fixes #3548
Motivation and Context
In a cycle of classes and unions, only the classes were forward-declared,
and a class could refer to a union class that was declared after it.
test/inputs/schema/recursive-union-flattening.schemagenerated a filethat fails to load with
uninitialized constant X::XElement (NameError).Previous Behaviour / Output
and
requirefails withNameError.New Behaviour / Output
The file loads and round-trips
recursive-union-flattening.1.json.Other Ruby output changes too: across the repository's schema inputs,
mutually-recursive.schema,rust-cycle-breaker-union.schema,union-list.schemaandvega-lite.schemaget forward declarations fortheir union classes, and their types are declared in a different order.
They loaded before and still do. No other language changes.
How Has This Been Tested?
The existing input
recursive-union-flattening.schemacovers the bug inthe
schema-rubyfixture; no new input was needed. CI runsruby,schema-ruby-syntax, which only checks the syntax, so it does notrun this case; the full
schema-rubyfixture does.Environment: macOS 26.6 (arm64), Node 24.16.0, Ruby 4.0.6 with the
fixture's locked gems plus
bigdecimalandlogger(Ruby 4 no longerloads them by default, and dry-types needs them).
On this branch:
npm ci,npm run build,npm run lint(passes),npm run test:unit(54 files, 241 tests pass).
QUICKTEST=true FIXTURE=ruby,schema-ruby,schema-ruby-syntax npm run test:fixtures:all 143 tests pass (54
ruby, 88schema-ruby, 1schema-ruby-syntax).On master (c39af7d):
QUICKTEST=true FIXTURE=schema-ruby npm run test:fixtures -- test/inputs/schema/recursive-union-flattening.schemafails with
uninitialized constant X::XElement (NameError); on thisbranch it passes.
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