Skip to content

Ruby AST: preserve ExceptionList node in RescueClause for 2+ exceptions#22014

Open
Copilot wants to merge 4 commits into
mainfrom
copilot/update-rescue-clause-exception-handling
Open

Ruby AST: preserve ExceptionList node in RescueClause for 2+ exceptions#22014
Copilot wants to merge 4 commits into
mainfrom
copilot/update-rescue-clause-exception-handling

Conversation

Copilot AI commented Jun 19, 2026

Copy link
Copy Markdown
Contributor

RescueClause previously flattened all exception types as direct children, discarding the intermediate Exceptions tree-sitter node. For 2+ exceptions, a new ExceptionList AST node now preserves that structure.

Behavior

Exceptions AST structure
0 Unchanged
1 Unchanged — single exception is a direct child via getException(0)
2+ NewExceptionList is a direct child via getExceptions(); individual exceptions accessed via ExceptionList.getException(n)
rescue FirstError, SecondError => e
  # Before: RescueClause -> getException(0) -> FirstError
  #                      -> getException(1) -> SecondError
  #
  # After:  RescueClause -> getExceptions() -> ExceptionList -> getException(0) -> FirstError
  #                                                          -> getException(1) -> SecondError

RescueClause.getException(int n) and getAnException() remain usable for all cases (delegates through ExceptionList for 2+). The CFG is unaffected.

Changes

  • AST.qll: Added TExceptionList(Ruby::Exceptions g) (only when strictcount > 1); added to TAstNodeReal, toGenerated, and TExpr
  • Expr.qll: New ExceptionList class with getException(int n); RescueClause.getException delegates through ExceptionList for 2+ case; new RescueClause.getExceptions(); getAChild updated to expose ExceptionList as the tree edge for 2+ case

Copilot AI changed the title Ruby AST: Add ExceptionList node for rescue clauses with 2+ exceptions Ruby AST: preserve ExceptionList node in RescueClause for 2+ exceptions Jun 19, 2026
Copilot AI requested a review from aschackmull June 19, 2026 09:51
@aschackmull aschackmull force-pushed the copilot/update-rescue-clause-exception-handling branch from 946b770 to 6fbb572 Compare June 19, 2026 11:27
@aschackmull aschackmull added the no-change-note-required This PR does not need a change note label Jun 19, 2026
@aschackmull aschackmull marked this pull request as ready for review June 19, 2026 11:31
@aschackmull aschackmull requested a review from a team as a code owner June 19, 2026 11:31
Copilot AI review requested due to automatic review settings June 19, 2026 11:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Ruby AST modeling to preserve the intermediate tree-sitter Exceptions node for rescue clauses that specify two or more exception types, by introducing a new ExceptionList AST node. This helps maintain the original syntactic structure instead of flattening exception types directly under RescueClause.

Changes:

  • Introduces a new ExceptionList AST node for rescue clauses with 2+ exceptions and exposes it via RescueClause.getExceptions().
  • Updates RescueClause.getException(int) to remain usable across 0/1/2+ exception cases by delegating through ExceptionList for 2+.
  • Extends library tests/fixtures to include a rescue clause with multiple exceptions and updates expected outputs accordingly.
Show a summary per file
File Description
ruby/ql/lib/codeql/ruby/ast/internal/AST.qll Adds internal TExceptionList node kind and wires it into the generated AST node sets.
ruby/ql/lib/codeql/ruby/ast/Expr.qll Introduces ExceptionList and updates RescueClause APIs/child edges for 2+ exceptions.
ruby/ql/test/library-tests/ast/calls/calls.rb Adds a begin … rescue foo, X::bar … ensure … end fixture to exercise the 2+ exception case.
ruby/ql/test/library-tests/ast/Ast.expected Updates printed AST expectations to include the new ExceptionList node/edge.
ruby/ql/test/library-tests/ast/TreeSitter.expected Updates tree-sitter parse-tree expectations for the modified fixture file layout.
ruby/ql/test/library-tests/ast/ValueText.expected Updates constant-value expectations due to fixture line shifts.
ruby/ql/test/library-tests/ast/calls/calls.expected Updates call expectations due to fixture line shifts/new construct.
ruby/ql/test/library-tests/ast/calls/arguments.expected Updates argument expectations due to fixture line shifts.
ruby/ql/test/library-tests/ast/AstDesugar.expected Updates desugaring expectations due to fixture line shifts.

Copilot's findings

  • Files reviewed: 9/9 changed files
  • Comments generated: 0

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

Labels

no-change-note-required This PR does not need a change note Ruby

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants