From bce952f9d2079f2f3970ae0c1a5a3fefe42f3558 Mon Sep 17 00:00:00 2001 From: EloB <476567+EloB@users.noreply.github.com> Date: Sun, 15 Nov 2026 07:47:25 +0100 Subject: [PATCH] fix(ruby): forward-declare union classes 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 --- packages/quicktype-core/src/language/Ruby/RubyRenderer.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/quicktype-core/src/language/Ruby/RubyRenderer.ts b/packages/quicktype-core/src/language/Ruby/RubyRenderer.ts index 238674be59..bce64e9075 100644 --- a/packages/quicktype-core/src/language/Ruby/RubyRenderer.ts +++ b/packages/quicktype-core/src/language/Ruby/RubyRenderer.ts @@ -56,8 +56,11 @@ export class RubyRenderer extends ConvenienceRenderer { return true; } + // Classes and the unions that are emitted as classes (emitUnion) can be + // forward declared with `class Name < Dry::Struct; end`. protected canBeForwardDeclared(t: Type): boolean { - return t.kind === "class"; + if (t.kind === "class") return true; + return t.kind === "union" && this.unionNeedsName(t as UnionType); } protected forbiddenNamesForGlobalNamespace(): readonly string[] {