Skip to content

Propagate predicate types to pattern variables#110

Merged
dak2 merged 1 commit intomainfrom
pattern-variable-type-propagation
Apr 5, 2026
Merged

Propagate predicate types to pattern variables#110
dak2 merged 1 commit intomainfrom
pattern-variable-type-propagation

Conversation

@dak2
Copy link
Copy Markdown
Owner

@dak2 dak2 commented Apr 5, 2026

Motivation

Pattern variables in case...in were always assigned Type::Bot, discarding the predicate's type information. This meant type errors inside pattern match bodies went undetected.

Changes

  • Thread predicate_vtx from process_case_match_node through pattern processing chain
  • Extract element types from Array[T] / Hash[K, V] predicates for array/hash/find patterns
  • Use Type::hash() instead of Type::instance("Hash") for consistency

Checked

  • cargo test --lib
  • bundle exec ruby -Ilib -Itest test/pattern_matching_test.rb

🤖 Generated with Claude Code

@dak2 dak2 force-pushed the pattern-variable-type-propagation branch 3 times, most recently from 78e2a66 to cf6d2cf Compare April 5, 2026 12:17
Previously, all pattern variables (e.g., `in x`, `in [x, y]`) were
assigned `Type::Bot`, losing the predicate's type information. Now
the predicate VertexId is threaded through the pattern processing
chain so variables inherit the correct type.

Why: enables type error detection in pattern match bodies (e.g.,
`case 42; in x; x.upcase; end` now correctly reports an error).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@dak2 dak2 force-pushed the pattern-variable-type-propagation branch from cf6d2cf to 5c86bba Compare April 5, 2026 12:39
@dak2 dak2 merged commit c69c84d into main Apr 5, 2026
4 checks passed
@dak2 dak2 deleted the pattern-variable-type-propagation branch April 5, 2026 12:45
@dak2 dak2 added this to the v0.2.0 milestone Apr 5, 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