Small naming cleanup surfaced while reviewing #1243 / PR #1249.
Every AST node's visitor handler follows the mechanical rule Visit + node type name (Stmt.Var→VisitVar, Expr.Binary→VisitBinary, …). Stmt.Expression is the one exception, and only in the analyzer-visitor family:
| Family |
Handler for Stmt.Expression |
Analyzer visitors (AstVisitorBase + subclasses) |
VisitExpressionStmt |
Registry dispatch (Interpreter, TypeChecker, via NodeRegistry.AutoRegister's $"Visit{Name}") |
VisitExpression |
So the same node type has two different handler names depending on the subsystem. It's the only node where the two families disagree.
Not a bug — each family is internally consistent (AstVisitorBase's switch calls VisitExpressionStmt and that method exists; AutoRegister looks for VisitExpression on the interpreter/type-checker and those exist). The Stmt suffix was likely chosen to avoid the read-ambiguity of "VisitExpression" looking like "visit an Expr."
Why unify: it's the last divergence from the otherwise-uniform Visit{Name} convention, and it's the one thing a future source-generator-based dispatch (the road not taken in #1243) would have to special-case. Unifying removes that wrinkle.
Scope — rename VisitExpressionStmt → VisitExpression, 4 internal spots (behavior-neutral, near-zero risk; AstVisitorBase is not a public package API):
Parsing/Visitors/AstVisitorBase.cs — the Stmt.Expression switch case (~:94)
Parsing/Visitors/AstVisitorBase.cs — the method definition (~:434)
Compilation/StringAccumulatorPromotionAnalyzer.cs — the override (~:111)
Compilation/StringAccumulatorPromotionAnalyzer.cs — the base.VisitExpressionStmt(stmt) call (~:127)
Only argument against: slight readability loss ("VisitExpression" reading as an Expr visit).
Part of #1094.
Small naming cleanup surfaced while reviewing #1243 / PR #1249.
Every AST node's visitor handler follows the mechanical rule
Visit+ node type name (Stmt.Var→VisitVar,Expr.Binary→VisitBinary, …).Stmt.Expressionis the one exception, and only in the analyzer-visitor family:Stmt.ExpressionAstVisitorBase+ subclasses)VisitExpressionStmtInterpreter,TypeChecker, viaNodeRegistry.AutoRegister's$"Visit{Name}")VisitExpressionSo the same node type has two different handler names depending on the subsystem. It's the only node where the two families disagree.
Not a bug — each family is internally consistent (
AstVisitorBase's switch callsVisitExpressionStmtand that method exists;AutoRegisterlooks forVisitExpressionon the interpreter/type-checker and those exist). TheStmtsuffix was likely chosen to avoid the read-ambiguity of "VisitExpression" looking like "visit anExpr."Why unify: it's the last divergence from the otherwise-uniform
Visit{Name}convention, and it's the one thing a future source-generator-based dispatch (the road not taken in #1243) would have to special-case. Unifying removes that wrinkle.Scope — rename
VisitExpressionStmt→VisitExpression, 4 internal spots (behavior-neutral, near-zero risk;AstVisitorBaseis not a public package API):Parsing/Visitors/AstVisitorBase.cs— theStmt.Expressionswitch case (~:94)Parsing/Visitors/AstVisitorBase.cs— the method definition (~:434)Compilation/StringAccumulatorPromotionAnalyzer.cs— the override (~:111)Compilation/StringAccumulatorPromotionAnalyzer.cs— thebase.VisitExpressionStmt(stmt)call (~:127)Only argument against: slight readability loss ("
VisitExpression" reading as anExprvisit).Part of #1094.