Repository navigation
Restore the Rust trait and Go interface flags when a member throws [patch] - #360
Merged
Merged
Conversation
…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
|
This was referenced Oct 30, 2026
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.



Fixes #357
Fixes #359
What changed
Three flags were set and cleared with plain assignments, without a
try/finally:RustGenerator.insideTraitRustGenerator.insideTraitImplementationGoGenerator.insideInterfaceGenerators 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:
pubwas dropped, and an empty free function became the file-scopefn f();, which rustc rejects.funcand no body.Each flag is now saved and restored in
finally. This is the same pattern #342 used forinsideTypeand the C# generator uses forinReadOnlyStruct.Tests
FailedGenerationStateTestshas three new cases. In each, generation throws inside the construct, and then a document withfn Answer() -> int { return 1 }and an emptyNoop()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.Testsuite passes locally: 1554 tests, 0 failures.Generated by Claude Code