From a7decf5f049ffa246445da785d4c16c320cf1b79 Mon Sep 17 00:00:00 2001 From: Takumi Shotoku Date: Sat, 5 Sep 2026 17:48:09 +0900 Subject: [PATCH] Support a lambda pattern `in ->(x) { ... }` matches by `===`, but AST.create_pattern_node had no branch for :lambda_node and raised "unknown pattern node type: lambda_node". Route it through the same install_pattern0 path as the other value patterns; CaseMatchNode#install0 discards the pattern's return value, so returning a proc instead of the subject is harmless. The subject is not passed to the lambda, so its parameter stays untyped and the body is not checked against the matched value. --- lib/typeprof/core/ast.rb | 1 + scenario/patterns/lambda_pat.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 scenario/patterns/lambda_pat.rb diff --git a/lib/typeprof/core/ast.rb b/lib/typeprof/core/ast.rb index 8420c3881..f13e34b6b 100644 --- a/lib/typeprof/core/ast.rb +++ b/lib/typeprof/core/ast.rb @@ -396,6 +396,7 @@ def self.create_pattern_node(raw_node, lenv) when :array_node then ArrayNode.new(raw_node, lenv) # for %w[foo bar] when :range_node then RangeNode.new(raw_node, lenv) # TODO: support range pattern correctly + when :lambda_node then LambdaNode.new(raw_node, lenv) # TODO: match by `===` instead of ignoring the subject else raise "unknown pattern node type: #{ raw_node.type }" diff --git a/scenario/patterns/lambda_pat.rb b/scenario/patterns/lambda_pat.rb new file mode 100644 index 000000000..dba64ca74 --- /dev/null +++ b/scenario/patterns/lambda_pat.rb @@ -0,0 +1,16 @@ +## update: test.rb +def check(x) + case x + in ->(i) { i == 0 } + :zero + in Integer + :int + end +end + +check(0) + +## assert +class Object + def check: (Integer) -> (:int | :zero) +end