Skip to content

Restore the Rust trait and Go interface flags when a member throws [patch] - #360

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/357-restore-trait-interface-flags
Nov 4, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/357-restore-trait-interface-flags

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #357
Fixes #359

What changed

Three flags were set and cleared with plain assignments, without a try/finally:

  • RustGenerator.insideTrait
  • RustGenerator.insideTraitImplementation
  • GoGenerator.insideInterface

Generators are singletons. If a member threw while one of these flags was set, the flag stayed set on that instance, and every later document generated on it came out wrong:

  • Rust: pub was dropped, and an empty free function became the file-scope fn f();, which rustc rejects.
  • Go: free functions came out as bare signatures, with no func and no body.

Each flag is now saved and restored in finally. This is the same pattern #342 used for insideType and the C# generator uses for inReadOnlyStruct.

Tests

FailedGenerationStateTests has three new cases. In each, generation throws inside the construct, and then a document with fn Answer() -> int { return 1 } and an empty Noop() must come out exactly as it would from a fresh instance:

  • RustGenerator_AfterAFailureInsideATrait_…: an interface method returns an unknown binary operator.
  • RustGenerator_AfterAFailureInsideASpecialisation_…: the same method, inside a specialisation (impl X for Y).
  • GoGenerator_AfterAFailureInsideAnInterface_…: an interface method has an optional parameter whose default uses the unknown operator.

With the generator changes reverted, all three new tests fail. With the changes in place, the full Coder.Test suite passes locally: 1554 tests, 0 failures.


Generated by Claude Code

…atch]

insideTrait, insideTraitImplementation (Rust) and insideInterface (Go) were set
and cleared with plain assignments, so a member that threw left the flag set on
the singleton generator. Every later document on that instance then lost `pub`
in Rust, wrote file-scope `fn f();`, or wrote Go free functions as bare
signatures. Each is now saved and restored in finally, as #342 did for
insideType.

Fixes #357
Fixes #359

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017vfJW2iVGcootGPPjA4P7Q
@sonarqubecloud

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants