Skip to content

ast: add Node#deconstruct, fix hash - #1105

Merged
github-actions[bot] merged 1 commit into
ruby:mainfrom
apiology:ast-node-deconstruct-hash
Oct 17, 2026
Merged

github-actions[bot] merged 1 commit into
ruby:mainfrom
apiology:ast-node-deconstruct-hash

Conversation

@apiology

Copy link
Copy Markdown
Contributor

Claude: This PR was written by Claude Code on behalf of @apiology.

Problem:

Steep mistypes AST::Node#hash and lacks deconstruct:

# test.rb:17:9: [error] Cannot pass a value of type `::String` as an argument of type `::Integer`
Integer! node1.hash
# test.rb:28:14: [error] Type `::AST::Node` does not have method `deconstruct`
Array!  node1.deconstruct

Nodes used as hash keys or in array patterns get wrong or missing types.

Solution:

Type hash as Integer and add deconstruct: () -> Array[untyped], matching AST::Node in ast v2.4.3, where hash is [@type, @children, self.class].hash and deconstruct returns [type, *children].

Node#hash is [type, children, class].hash, an Integer, not a String.
Node#deconstruct returns [type, *children] for pattern matching, as
in ast 2.4.2 and 2.4.3.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01GgkyXKEZWpEFXo6ceA5MSw
@apiology
apiology marked this pull request as ready for review October 16, 2026 22:12
@github-actions

Copy link
Copy Markdown

@apiology Thanks for your contribution!

Please follow the instructions below for each change.
See also: https://github.com/ruby/gem_rbs_collection/blob/main/docs/CONTRIBUTING.md

Available commands

You can use the following commands by commenting on this PR.

  • /merge: Merge this PR if CI passes

ast

You changed RBS files for an existing gem.
You need to get approval from the reviewers of this gem.

@pocke, @kozy4324, please review this pull request.
If this change is acceptable, please make a review comment including APPROVE from here.
Screen Shot 2024-03-19 at 14 13 36

After that, the PR author or the reviewers can merge this PR.
Just comment /merge to merge this PR.

@kozy4324 kozy4324 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.

APPROVE

@github-actions

Copy link
Copy Markdown

Thanks for your review, @kozy4324!

@apiology, @kozy4324 This PR is ready to be merged.
Just comment /merge to merge this PR.

@apiology

Copy link
Copy Markdown
Contributor Author

/merge

@github-actions
github-actions Bot merged commit 2ed83ff into ruby:main Oct 17, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants