Repository navigation
Spell C# access modifiers C# allows where each declaration stands [patch] - #455
Merged
Merged
Conversation
…tch] A private or protected type in a namespace or file is internal (CS1527), a protected member of the static holder class is internal (CS1057), and a protected member of a struct is private (CS0666). Each changed modifier is written down in a note above the declaration. Members of classes and interfaces are unchanged. Fixes #428 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW58CbYAhSAZyBsuJtr
This was referenced Nov 7, 2026
Keeps main's typeless-list fallback in GenerateVariableDeclaration ahead of the positioned access modifier, and both sides' appended tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW58CbYAhSAZyBsuJtr
Keeps #454's appended C# compile test beside this branch's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW58CbYAhSAZyBsuJtr
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW5jpiuVuBRXSgitSY1
Keeps the C# compile tests main appended (#451) beside this branch's. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW58CbYAhSAZyBsuJtr
|
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 #428
What was wrong
CSharpGeneratorwrote each declaration'sVisibilityexactly as given, wherever the declaration sat. ASTs that are valid for C++ therefore produced C# that doesn't compile:private/protectedtype or enum directly in a namespace or file: CS1527.protectedfield or function moved into the generatedpublic static classholder: CS1057.protectedmember of a struct: CS0666.Change
There is now one rule,
ForbiddenAccess, that decides by position.SpellAccesswrites the modifier it allows, andWriteForbiddenAccessNotewrites aWriteInexpressiblenote above the declaration, the same way operators already do (#260).private,protectedinternalprotectedinternal, so types beside it in the namespace still reach itprotectedprivate, which is allprotectedmeans where nothing can derivetypeMemberOwner, saved and restored next totypeMember, lets non-function members know which type encloses them.Tests
CSharpGeneratedSourceCompilesTests.ForbiddenAccessModifiers_Compilebuilds every row of the issue's table plus a nested type in a struct. It runsdotnet buildwith a driver that calls the holder's members, and checks the notes. It also checks that aprotectedmember of a class staysprotected.Generated by Claude Code