Repository navigation
Write C# operators public static, noting a dropped visibility or virtual [patch] - #264
Merged
Merged
Conversation
…ual [patch] C# requires a user-defined operator to be public and static, and allows neither virtual nor abstract on one outside an interface. The generator wrote a private or protected operator's visibility unchanged (CS0558) and a virtual or abstract one's modifier unchanged (CS0106). Operators and conversion operators are now always public static, with a note above the declaration naming what C++ allowed and C# cannot say. Fixes #260 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0175VbFC9TAs3FcivXVHTFum
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0175VbFC9TAs3FcivXVHTFum
|
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 #260
Before:
CSharpGenerator.WriteFunctionModifierscopied an operator's declared visibility and itsvirtual/abstractflags straight into the output. C++ allows a private or virtual member operator, so that AST producedprivate static Point operator +(...)(CS0558) orpublic static virtual ...(CS0106).After: an
OperatororConversionOperatoris always writtenpublic static.virtualandabstractare dropped outside interfaces; interface operators behave as before.WriteMemberNotesadds a note above the declaration for anything dropped, for example// private: operator + is public, as every C# operator isor// virtual: operator - is static, which a C# operator outside an interface cannot override.Tests:
CSharpGeneratedSourceCompilesTests.OperatorsDeclaredPrivateOrVirtual_Compilebuilds the generated code withdotnet build: a private binary operator, a virtual unary operator and a protected conversion operator onPoint. It also checks that the notes are present.CSharpMemberModifierTests.AbstractProtectedOperatorInAClass_IsPublicStaticWithANotecovers the abstract and protected case.Note: open PR #246 also edits C# operator generation, but in a different part of the code, so any overlap should be small.
Generated by Claude Code