codegen.c: raise NoMatchingPatternError in case/in without else

case/in without else clause now raises NoMatchingPatternError
when no pattern matches, matching CRuby behavior. Fixes #6741.

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2026-03-12 14:28:01 +09:00
parent b34b7206f9
commit d8de35b635
2 changed files with 9 additions and 9 deletions
+3 -4
View File
@@ -4455,10 +4455,9 @@ codegen_case_match(codegen_scope *s, node *varnode, int val)
current_in = current_in->cdr;
}
/* No pattern matched - generate nil or error */
if (val) {
genop_1(s, OP_LOADNIL, cursp());
}
/* No pattern matched - raise NoMatchingPatternError */
genop_1(s, OP_LOADFALSE, cursp());
genop_1(s, OP_MATCHERR, cursp());
/* Dispatch all end jumps */
if (case_end_jumps != JMPLINK_START) {
+6 -5
View File
@@ -1246,12 +1246,13 @@ assert('pattern matching - NoMatchingPatternError') do
assert_true e.message.is_a?(String)
end
# case/in without else returns nil (no match)
result = case 5
in 1 then :one
in 2 then :two
# case/in without else raises NoMatchingPatternError
assert_raise(NoMatchingPatternError) do
case 5
in 1 then :one
in 2 then :two
end
end
assert_nil result
end
assert('pattern matching - complex patterns') do