Repository navigation
Description
What's wrong
self is an ordinary identifier in C# and in the AST, but the generators treat it as the receiver. There are two separate failures.
1. The parameter collides with the receiver the generator inserts (Python, Go).
- Python
WriteMethodSignaturealways writesselffirst, then the declared parameters:Coder/Coder/Languages/PythonGenerator.cs
Lines 829 to 845 in 89d8424
bool needsSeparator = !method.IsStatic; if (needsSeparator) { code.Write("self"); } for (int index = 0; index < method.Parameters.Count; index++) { if (needsSeparator) { code.Write(", "); } GenerateParameter(method.Parameters[index], code, index); needsSeparator = true; } - Go names every method receiver
self:Coder/Coder/Languages/GoGenerator.cs
Line 81 in 89d8424
private const string ReceiverName = "self"; - Neither generator renames a user parameter or local that has the same name.
2. The declaration is escaped but references to it are not (Rust, C++).
self(Rust) andthis(C++) are inReservedWords, so the parameter declaration goes throughEscapeIdentifierand becomesself_/this_.EscapeReferencedeliberately skips segment 0 whenIsReceiverWordmatches:Coder/Coder/Languages/LanguageGeneratorBase.cs
Lines 1217 to 1223 in 89d8424
string[] segments = reference.Split('.'); for (int i = 0; i < segments.Length; i++) { if (ReservedWords.Contains(segments[i]) && !(i == 0 && IsReceiverWord(segments[i]))) { segments[i] = EscapeIdentifier(segments[i]); } - So a
VariableReference("self")that names the parameter is written as the bare receiver word. IsReceiverWordoverrides:andCoder/Coder/Languages/RustGenerator.cs
Line 375 in 89d8424
protected override bool IsReceiverWord(string word) => word is "self" or "Self" or "crate" or "super" or "true" or "false"; Coder/Coder/Languages/CppGenerator.cs
Line 137 in 89d8424
protected override bool IsReceiverWord(string word) => word is "this" or "true" or "false" or "nullptr";
Failure scenario
Input: a class Vec with a method int dot(int self) { return self * 2; }, and a free function int twice(int self) { return self + self; }.
| Target | Output | Result |
|---|---|---|
| Python | def dot(self, self: int) |
SyntaxError: duplicate argument 'self' |
| Go | func (self *Vec) dot(self int) int |
self redeclared in this block |
| Rust (free fn) | pub fn twice(self_: i32) -> i32 { return (self + self); } |
E0424 self is not available in a non-method |
| Rust (method) | self * 2 |
E0369, since self is &mut Vec and not the i32 parameter |
C++ (param this) |
int twice(int this_) { return (this + this); } |
does not compile |
Suggested fix
- When a parameter or local has the target's receiver name (
selfin Python/Go/Rust,thisin C++), rename it with the escaped spelling at its declaration. Make everyVariableReferencethat resolves to that parameter or local use the same spelling. - In
EscapeReference, apply theIsReceiverWordexemption only when segment 0 is not a parameter or local in scope. That keeps the promise in the doc comment that a declaration and its uses can't come out spelled differently.
Acceptance criteria
- Each case above produces output that parses or compiles in Python (
py_compile), Go (go vet), Rust (rustc) and C++ (g++ -fsyntax-only). - A body that genuinely refers to the receiver (
self.xinside a method, with no parameter namedself) is unchanged.
Activity
matt-edmondson commentedon Oct 31, 2026
Triage
self, orthisfor C++, and the failure is loud rather than silent.Coder/Languages/LanguageGeneratorBase.cs(EscapeReference/IsReceiverWord),PythonGenerator.WriteMethodSignature, the Go receiver naming, and theIsReceiverWordoverrides in Rust and C++.LanguageGeneratorBase.Generated by Claude Code