Skip to content

feat(go): read union base-property dedupe facts from the IR#17042

Draft
fern-support wants to merge 1 commit into
will/union-base-props-irfrom
will/union-base-props-go
Draft

feat(go): read union base-property dedupe facts from the IR#17042
fern-support wants to merge 1 commit into
will/union-base-props-irfrom
will/union-base-props-go

Conversation

@fern-support

Copy link
Copy Markdown
Collaborator

Description

Linear ticket: Refs

PR 2 of 3 (stacked on the IR PR #17041). Makes the Go v1 model consume the discriminated-union base-property dedupe decision from the IR instead of re-deriving it. Companion to #17041 (IR facts) and the C# PR.

DRAFT — blocked. Base is will/union-base-props-ir (#17041), not main. This does nothing at runtime until (1) the new IR minor publishes and (2) go-sdk moves from irVersion: 6667 — today the CLI migrates the IR down to v66 and strips these fields before the Go generator sees them. Merge order: #17041 → publish → go-sdk IR-67 upgrade → this.

Changes Made

  • internal/generator/model.go: rewrote unionInheritedBasePropertyNames to read union.InheritedBaseProperties (computed once in the IR) instead of re-deriving it from the variants. Deleted everyVariantHasMatchingGetter and objectExportedProperties. Kept writeUnionInheritedBasePropertyGetters (getter emission is Go policy) and a thin local filter that keeps literal-typed inherited properties on the envelope (they render as methods, not delegatable fields).
  • internal/fern/ir/types.go: hand-added the InheritedBaseProperties field + getter to the vendored UnionTypeDeclaration (stand-in for regenerating the vendored structs from the published IR).
  • internal/generator/model_union_test.go: refocused the unit test on the Go side's consumption (flag gate, literal local filter, name mapping); the "which props are inherited" decision is now covered by the IR-generator tests in feat(ir): compute discriminated-union base-property dedupe facts in the IR #17041.
  • Go SDK changelog entry.
  • Updated README.md generator (if applicable) — N/A

Behavior note

Go previously deduped on rendered-Go-type equality (a superset of the IR's structural equality). Reading inheritedBaseProperties means Go dedupes strictly fewer cases — a few previously-suppressed fields may reappear on the envelope. This is safe (it can only keep a field, never drop a needed one → no go vet regressions) and removes the drift between the Go model and the Go dynamic snippets.

Remaining before this can merge

Testing

  • Unit test updated (model_union_test.go) — not executed locally (no Go toolchain); runs in CI once unblocked.

Generated with Claude Code

Consume UnionTypeDeclaration.InheritedBaseProperties (computed once upstream in
the IR) in the Go model instead of re-deriving the dedupe decision from the
variants. Delete the re-derivation helpers everyVariantHasMatchingGetter and
objectExportedProperties; keep the delegating-getter emission
(writeUnionInheritedBasePropertyGetters) and a thin local filter that keeps
literal-typed inherited properties on the envelope (they render as methods, not
delegatable fields). Gate stays on the opt-in dedupeUnionBaseProperties flag.

Hand-adds the InheritedBaseProperties field to the vendored IR struct; the final
step (post IR publish) is to regenerate generators/go/internal/fern/ir from the
published IR and move go-sdk to irVersion 67 so the field is populated at runtime.

BLOCKED: stacks on the IR PR (#17041). Does nothing at runtime until (1) the new
IR minor publishes and (2) go-sdk moves from irVersion 66 to 67 (today the CLI
migrates the IR down to v66 and strips these fields). Go build/test not run
locally (no Go toolchain in this environment); gofmt the vendored struct on regen.

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants