Commit 860bad77

860bad77bae8Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified

Description

Merge pull request #954 from ryanseys/rs-pattern-no-match-error

codegen: case/in raises NoMatchingPatternError on exhaustive miss

Details

Commit
860bad77bae8
Parent
268c9fa0dbe7
Merge parent
cd4d3f6bf26f

spinel_codegen.rbmodifiedView file

@@ -8567,6 +8567,8 @@
85678567 ["SystemCallError", "StandardError"],
85688568 ["LocalJumpError", "StandardError"],
85698569 ["FiberError", "StandardError"],
8570+ ["NoMatchingPatternError", "StandardError"],
8571+ ["NoMatchingPatternKeyError", "NoMatchingPatternError"],
85708572 ["Exception", ""],
85718573 ]
85728574 bp = 0
@@ -33061,6 +33063,17 @@
3306133063 @indent = @indent + 1
3306233064 compile_stmts_body(@nd_body[ec])
3306333065 @indent = @indent - 1
33066+ elsif conds.length > 0
33067+ # No `else` clause: CRuby raises NoMatchingPatternError when no
33068+ # `in` arm matched. The message includes the inspected scrutinee
33069+ # value (we drop the `=== val does not return true` tail since
33070+ # spinel doesn't carry the pattern's source text at codegen).
33071+ ins_msg = compile_inspect_for(pred_type, tmp)
33072+ if ins_msg != ""
33073+ emit(" } else { sp_raise_cls(\"NoMatchingPatternError\", " + ins_msg + ");")
33074+ else
33075+ emit(" } else { sp_raise_cls(\"NoMatchingPatternError\", \"no matching pattern\");")
33076+ end
3306433077 end
3306533078 if conds.length > 0
3306633079 emit(" }")