Skip to content

Add pattern matching type inference#103

Merged
dak2 merged 1 commit into
mainfrom
feature/pattern-matching
Mar 28, 2026
Merged

Add pattern matching type inference#103
dak2 merged 1 commit into
mainfrom
feature/pattern-matching

Conversation

@dak2

@dak2 dak2 commented Mar 28, 2026

Copy link
Copy Markdown
Owner

Motivation

Pattern matching was not supported by MethodRay, causing it to silently skip type inference for matched variables.

Changes

  • Add CaseMatchNode processing with support for all pattern types: capture, array, hash, find, alternation, pinned variable/expression, guard (if), and literal
  • Fix hash shorthand { name: } binding via ImplicitNode unwrapping
  • Fix capture pattern to handle namespaced constants (Api::User => u) via extract_constant_path
  • Fix hash splat **rest to read from HashPatternNode.rest() instead of elements()
  • Unify all variable bindings through install_local_var_write for consistent ChangeSet edge propagation
  • Remove unreachable UnlessNode guard branch (Ruby does not support unless guards in case/in)

Checked

  • cargo test --lib (44 passed)
  • bundle exec ruby -Ilib -Itest test/pattern_matching_test.rb (18 passed)

@dak2 dak2 force-pushed the feature/pattern-matching branch 2 times, most recently from c3217b5 to 13c5057 Compare March 28, 2026 06:04
@dak2 dak2 changed the title Add pattern matching (case...in) type inference Add pattern matching type inference Mar 28, 2026
@dak2 dak2 force-pushed the feature/pattern-matching branch 3 times, most recently from 12f9d0d to b4744db Compare March 28, 2026 06:19
Pattern matching was not supported by MethodRay,
causing it to silently skip type inference for matched variables.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dak2 dak2 force-pushed the feature/pattern-matching branch from b4744db to 3ad4448 Compare March 28, 2026 06:30
@dak2 dak2 merged commit 2c575fb into main Mar 28, 2026
4 checks passed
@dak2 dak2 deleted the feature/pattern-matching branch March 28, 2026 06:35
@dak2 dak2 added this to the v0.2.0 milestone Mar 28, 2026
@dak2 dak2 mentioned this pull request Apr 5, 2026
4 tasks
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.

1 participant