diff --git a/mrbgems/mruby-compiler/core/codegen.c b/mrbgems/mruby-compiler/core/codegen.c index 1b804a4f6..48cae6569 100644 --- a/mrbgems/mruby-compiler/core/codegen.c +++ b/mrbgems/mruby-compiler/core/codegen.c @@ -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) { diff --git a/test/t/syntax.rb b/test/t/syntax.rb index 42a6d4198..a02ca1d8a 100644 --- a/test/t/syntax.rb +++ b/test/t/syntax.rb @@ -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