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
Friend operator (IsFriend, two operands) generates a three-operand operator in C# (CS1534) and Rust (E0050) #231
FunctionDeclaration.IsFriend is documented as "declared inside a type but is not a member of it ... how a symmetric operator is written beside the type" (Coder/Ast/FunctionDeclaration.cs:~146-155). A friend operator therefore declares both of its operands itself. Two generators ignore that:
Rust: the operator-trait writer (Coder/Languages/RustGenerator.cs, ~:841-855) always writes self followed by every declared parameter.
Reproduction
A struct Point { int x } with an operator +, Kind = Operator, IsFriend = true, parameters a: Point, b: Point, returning a:
// C++ (correct)
friend Point operator+(Point a, Point b)
// C#
public static Point operator +(Point self, Point a, Point b) // error CS1534: Overloaded binary operator '+' takes two parameters
// Rust
impl std::ops::Add for Point { type Output = Point; fn add(self, a: Point, b: Point) -> Point {...} } // E0050
Both errors were confirmed with dotnet build and rustc. C and Go also gain a spurious receiver (Point_add(Point* self, Point a, Point b) and func (self *Point) Add(a, b)). Those compile, but don't match the declared arity.
Suggested fix
C#: return false from TakesImplicitOperand when function.IsFriend. The operator is already static.
Rust: when IsFriend, bind the first declared parameter as self (fn add(self, rhs: Point), rebinding the first parameter's name in the body), or write the operator out as unsupported.
C and Go: skip the receiver for friends, as WriteReceiver already does for IsStatic.
Add a friend + to CompiledExemplar and compile it in the C# and Rust compile tests.
Next step: Add an IsFriend guard in TakesImplicitOperand and WriteReceiver, and use first-parameter-as-self in Rust. Add a friend + to CompiledExemplar.
Activity
matt-edmondson commentedon Oct 17, 2026
Triage
+silently becomes unary+and unary/conversion operators fail with CS1019 #126)longmapping.IsFriendguard inTakesImplicitOperandandWriteReceiver, and use first-parameter-as-selfin Rust. Add a friend+toCompiledExemplar.Generated by Claude Code