GitHub

File tree

  • mrbgems/mruby-compiler/core

  • test/t

Original file line numberDiff line numberDiff line change

@@ -4455,10 +4455,9 @@ codegen_case_match(codegen_scope *s, node *varnode, int val)

44554455

current_in = current_in->cdr;

44564456

}

44574457
4458-

/* No pattern matched - generate nil or error */

4459-

if (val) {

4460-

genop_1(s, OP_LOADNIL, cursp());

4461-

}

4458+

/* No pattern matched - raise NoMatchingPatternError */

4459+

genop_1(s, OP_LOADFALSE, cursp());

4460+

genop_1(s, OP_MATCHERR, cursp());

44624461
44634462

/* Dispatch all end jumps */

44644463

if (case_end_jumps != JMPLINK_START) {

Original file line numberDiff line numberDiff line change

@@ -1246,12 +1246,13 @@ def self.cs3(x) = s3 x + 1

12461246

assert_true e.message.is_a?(String)

12471247

end

12481248
1249-

# case/in without else returns nil (no match)

1250-

result = case 5

1251-

in 1 then :one

1252-

in 2 then :two

1249+

# case/in without else raises NoMatchingPatternError

1250+

assert_raise(NoMatchingPatternError) do

1251+

case 5

1252+

in 1 then :one

1253+

in 2 then :two

1254+

end

12531255

end

1254-

assert_nil result

12551256

end

12561257
12571258

assert('pattern matching - complex patterns') do

Read the original on github.com ↗