catch a (never otherwise) bug I hadn't thought of

This commit is contained in:
2022-12-16 00:34:10 +00:00
parent d27107ad57
commit 1ee7f8db8b
2 changed files with 7 additions and 0 deletions

View File

@@ -344,6 +344,11 @@ class SpecialForms {
cases[i] = b.call(neverExps[0], [
b.callSymbol('throw', [
b.callSymbol('kiss.Prelude.runtimeInsertAssertionMessage', [b.str('${Reader.toString(neverExps[0].def)} should never match pattern ${Reader.toString(neverExps[0].def)}'), b.str(failureError), b.int(colonsInPrefix)])])]);
default:
}
}
for (i in 0...cases.length) {
switch (cases[i].def) {
case CallExp({pos: _, def: Symbol("otherwise")}, _) if (i != cases.length - 1):
throw KissError.fromExp(cases[i], "(otherwise <body...>) branch must come last in a (case <...>) expression");
default:

View File

@@ -363,6 +363,8 @@ From:[(assert false (+ \"false \" \"should \" \"have \" \"been \" \"true\"))]" m
(function _testCase []
// otherwise branch must come last
(assertThrowsAtCompileTime (case null (otherwise "thing") (v "OtherThing")))
// Even if it is in (never otherwise) form
(assertThrowsAtCompileTime (case null (never otherwise) (v "OtherThing")))
// null must be matched
(assertThrowsAtCompileTime (case null (v "thing")))
(case (toOption [])