You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
C#: a private/protected or virtual/abstract operator generates code that fails to compile (CS0558, CS0106) #260
CSharpGenerator.WriteFunctionModifiers (Coder/Languages/CSharpGenerator.cs:1008-1049) writes a function's declared visibility (around :1015) and its virtual/abstract flags (around :1034) unchanged, even for Operator and ConversionOperator functions. C# requires user-defined operators to be public static and does not allow virtual or abstract on them. #126 made operators static, but it neither forces public nor drops virtual/abstract.
Reproduction (main @ 440ef35, output compiled with dotnet build)
Struct Point with an operator + (Kind = Operator, Visibility = Private, parameter rhs: Point):
Generated: private static Point operator +(Point self, Point rhs)
Result: CS0558, "User-defined operator must be declared static and public".
The same operator with IsVirtual = true on a class Shape:
Generated: public static virtual Shape operator +(...)
Result: CS0106, "The modifier 'virtual' is not valid for this item".
C++ allows private and virtual member operators, so an AST written in C++ terms produces C# that doesn't build.
Suggested fix / acceptance criteria
For Operator and ConversionOperator, always write public static. Write a WriteInexpressible-style note when the declared visibility is not public, or when IsVirtual or IsAbstract is set.
Add compile tests: a private operator and a virtual operator both produce C# that builds, with the note present.
Related: #126 and #236 (other C# operator generation issues).
Priority: Medium. Private or virtual member operators are legal C++, and they produce C# that fails with CS0558 or CS0106. The failure is loud, the fix is small, and the issue gives clear acceptance criteria.
Area / suggested assignee:CSharpGenerator.WriteFunctionModifiers. Owner: @matt-edmondson
Next step: always write public static for Operator and ConversionOperator, and add an inexpressible note when the declared visibility or virtual/abstract is dropped. Add the two compile tests.
Activity
matt-edmondson commentedon Oct 18, 2026
Triage
CSharpGenerator.WriteFunctionModifiers. Owner: @matt-edmondson+silently becomes unary+and unary/conversion operators fail with CS1019 #126, C#: declaring only one of a comparison operator pair (==/!=, </>, <=/>=) generates code that fails with CS0216 #236 and C#: a free (non-member) operator at file or namespace scope is put insidestatic class Globals, which fails with CS0715 #261. Open PR Write the missing side of a C# comparison operator pair [patch] #246 changes C# operator generation, but it does not forcepublicor stripvirtual/abstract, so expect a small merge overlap in the same method.public staticforOperatorandConversionOperator, and add an inexpressible note when the declared visibility orvirtual/abstractis dropped. Add the two compile tests.Generated by Claude Code