From 1557590ed22ddbe7e638975fc95be03f23cd8c2f Mon Sep 17 00:00:00 2001 From: Nick Nassiri Date: Sat, 4 Jul 2026 17:20:32 -0700 Subject: [PATCH] refactor(ast): unify AstVisitorBase Stmt.Expression handler name (#1250) Rename VisitExpressionStmt -> VisitExpression in the analyzer-visitor family so it matches the mechanical Visit + node-type-name convention used everywhere else (Stmt.Var -> VisitVar, Expr.Binary -> VisitBinary). Stmt.Expression was the one node whose handler name diverged between the two dispatch families: AstVisitorBase's switch called VisitExpressionStmt while the registry dispatch (Interpreter/TypeChecker via NodeRegistry.AutoRegister's $"Visit{Name}") uses VisitExpression. This removes the last exception to the uniform naming and the one wrinkle a future source-generator-based dispatch would have to special-case. Behavior-neutral: renames the AstVisitorBase switch case, the virtual method, and the StringAccumulatorPromotionAnalyzer override + base call. No collision with the existing Interpreter/TypeChecker VisitExpression methods, which are not in the AstVisitorBase hierarchy. Part of #1094. Closes #1250 --- Compilation/StringAccumulatorPromotionAnalyzer.cs | 4 ++-- Parsing/Visitors/AstVisitorBase.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Compilation/StringAccumulatorPromotionAnalyzer.cs b/Compilation/StringAccumulatorPromotionAnalyzer.cs index 958d6521..234004a4 100644 --- a/Compilation/StringAccumulatorPromotionAnalyzer.cs +++ b/Compilation/StringAccumulatorPromotionAnalyzer.cs @@ -108,7 +108,7 @@ private void HandleDeclaration(Token name, Expr? initializer) Visit(initializer); } - protected override void VisitExpressionStmt(Stmt.Expression stmt) + protected override void VisitExpression(Stmt.Expression stmt) { // Permitted append in statement position (result discarded): `s = s + E` / `s += E` // with E statically string. Consume by visiting ONLY E — not the target, not the inner @@ -124,7 +124,7 @@ protected override void VisitExpressionStmt(Stmt.Expression stmt) Visit(ca.Value); return; } - base.VisitExpressionStmt(stmt); + base.VisitExpression(stmt); } protected override void VisitGet(Expr.Get expr) diff --git a/Parsing/Visitors/AstVisitorBase.cs b/Parsing/Visitors/AstVisitorBase.cs index 6d2168d7..b42bdbf5 100644 --- a/Parsing/Visitors/AstVisitorBase.cs +++ b/Parsing/Visitors/AstVisitorBase.cs @@ -91,7 +91,7 @@ public virtual void Visit(Stmt stmt) switch (stmt) { - case Stmt.Expression s: VisitExpressionStmt(s); break; + case Stmt.Expression s: VisitExpression(s); break; case Stmt.Var s: VisitVar(s); break; case Stmt.Const s: VisitConst(s); break; case Stmt.Function s: VisitFunction(s); break; @@ -431,7 +431,7 @@ protected virtual void VisitClassExpr(Expr.ClassExpr expr) #region Statement Visitors - Default implementations traverse children - protected virtual void VisitExpressionStmt(Stmt.Expression stmt) + protected virtual void VisitExpression(Stmt.Expression stmt) { Visit(stmt.Expr); }