Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion lib/typeprof/core/ast/pattern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,9 @@ def initialize(raw_node, lenv)
def subnodes = { cond:, body: }

def install_pattern0(genv, subject)
@cond.install(genv)
# The guard is evaluated after the pattern binds its variables
@body.install_pattern(genv, subject)
@cond.install(genv)
subject
end
end
Expand Down
30 changes: 30 additions & 0 deletions scenario/patterns/guard_binding.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## update: test.rb
def cond?(x)
x
end

def check_if(v)
case v
in [x] if cond?(x).even?
x
end
end

def check_unless(v)
case v
in [_, y] unless cond?(y).even?
y
end
end

check_if([1])
check_unless([:a, 1])

## diagnostics

## assert
class Object
def cond?: (Integer) -> Integer
def check_if: ([Integer]) -> Integer
def check_unless: ([:a, Integer]) -> Integer
end
Loading