Skip to content

Unify the AstVisitorBase Stmt.Expression handler name (VisitExpressionStmt → VisitExpression) #1250

Description

@nickna

Small naming cleanup surfaced while reviewing #1243 / PR #1249.

Every AST node's visitor handler follows the mechanical rule Visit + node type name (Stmt.VarVisitVar, Expr.BinaryVisitBinary, …). 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 VisitExpressionStmtVisitExpression, 4 internal spots (behavior-neutral, near-zero risk; AstVisitorBase is not a public package API):

  1. Parsing/Visitors/AstVisitorBase.cs — the Stmt.Expression switch case (~:94)
  2. Parsing/Visitors/AstVisitorBase.cs — the method definition (~:434)
  3. Compilation/StringAccumulatorPromotionAnalyzer.cs — the override (~:111)
  4. Compilation/StringAccumulatorPromotionAnalyzer.cs — the base.VisitExpressionStmt(stmt) call (~:127)

Only argument against: slight readability loss ("VisitExpression" reading as an Expr visit).

Part of #1094.

Metadata

Metadata

Assignees

No one assigned

    Labels

    tech-debtCode maintainability / tech-debt cleanup

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions