Skip to content

Calling a keyword-named function or method fails in Rust, C++ and Python: the declaration is escaped (r#match, delete_, lambda_) but the call is not #361

Closed

Description

@matt-edmondson

What's wrong

#330 and #347 escape a keyword-named function where it is declared. A CallExpression still writes its Callee verbatim, so every call to that function names something that no longer exists, or is a keyword.

  • Declarations are escaped: PythonGenerator.cs (def {EscapeIdentifier(...)}), RustGenerator.cs, CppGenerator.cs.
  • Calls are not:
    • LanguageGeneratorBase.GenerateCallExpression writes code.Write(callExpr.Callee) (Coder/Languages/LanguageGeneratorBase.cs:895).
    • Rust's pointer-receiver path writes .{callExpr.Callee}(.

Repro (HEAD 89d8424)

The input is a SourceFile with a free function kw(int a) -> int { return a; } and a function caller() -> int { return kw(1); }, with the call built as new CallExpression(kw):

Target (kw) Generated Result
Rust (match) pub fn r#match(a: i32) ... / return match(1); rustc: expected one of '.', '?', '{', or an operator
C++ (delete) int delete_(int a) / return delete(1); g++: type 'int' argument given to 'delete', expected pointer
Python (lambda) def lambda_(a: int) / return lambda(1) SyntaxError: invalid syntax

Method calls behave the same way:

  • Rust: a Holder method loop, called as new CallExpression(new VariableReference("self"), "loop"), generates pub fn r#loop(&mut self) and self.loop().
  • C++: a method named delete generates int delete_() and .delete().

ReservedWordIdentifierTests does not catch this, because its drivers hand-escape the calls (holder.r#type(), holder.default_()). No generated code in that test calls a keyword-named function.

Suggested fix / acceptance criteria

  • Escape the callee when it resolves to a function or method declared in the document. DeclaredFunction(call.Callee) and DeclaredMethod(StaticType(receiver), call.Callee) already do the resolution (StandardLanguageGenerator).
  • Leave all other callees verbatim. Callee is deliberately text, so names like std::sqrt, or C++'s sizeof and static_cast<int>, must not become sizeof_.
  • Cover both the base path and Rust's unsafe { (*p).callee() } path.
  • Extend ReservedWordIdentifierTests so the generated code itself calls a keyword-named free function and method, and compile or run that output with rustc, g++ and python.

Related: #106. This issue is a gap in the targets #106 records as done (Rust, C++, Python). It is not part of the remaining Go, JavaScript, C and C# work.

Activity

  1. added
    bug
    on Oct 30, 2026
  2. matt-edmondson commented on Oct 30, 2026

    @matt-edmondson
    ContributorAuthor

    Triage


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions