Repository navigation
Leave the inside-type count as it was when a type member throws [patch] - #346
Merged
Merged
Conversation
The C, C++ and Rust generators counted whether they were inside a type with a bare increment and decrement, so a member that threw left the count at 1 on the singleton instance. Every later Generate call then spelled file-scope declarations as members: C dropped a constant's value, C++ wrote static constexpr, and Rust wrote a struct field at file scope. The decrement now runs in a finally block. Fixes #342 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW1q2uCFhHjvcJTy9a2
|
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 #342
What changed
The C, C++ and Rust generators track whether they are inside a type with a bare
insideType++…insideType--. When a member threw partway through, the count stayed at 1 on the singleton instance. Every laterGeneratecall then treated file-scope declarations as members:static constexprinstead ofinline constexpr.pub limit: i32,at file scope.In
CppGenerator,CGeneratorandRustGenerator, the decrement now runs in afinally. The diff is mostly re-indentation of the loop body inside thetry.I used
try/finallyinstead of resetting the count at the top ofGenerate.Generatecan be re-entered (it saves and restoresGenerationRoot), so a reset there could clear the count in the middle of a type.Tests
FailedGenerationStateTestshas one test per generator. It runs a document that throws inside a type, then checks that a file-scope static constant generates exactly as it would on a fresh instance:Results:
Not in this PR
The issue also suggests auditing other per-call fields (
insideInterface/bodyDepthin Go,insideTraitin Rust,inReadOnlyStruct/namespacePathin C#). This PR covers only theinsideTypecounters the acceptance criteria name.Generated by Claude Code