diff --git a/evaluator.lua b/evaluator.lua index 361eba9..f9903d9 100644 --- a/evaluator.lua +++ b/evaluator.lua @@ -235,11 +235,15 @@ enum_desc_srel = setmetatable({ end local use_variants = use:unwrap_enum_desc_value() for name, val_type in val_variants:pairs() do + local use_variant = use_variants:get(name) + if use_variant == nil then + error(name .. " is not a valid enum variant! Is this a typo?") + end typechecker_state:queue_subtype( lctx, val_type, rctx, - use_variants:get(name) --[[@as value -- please find a better approach]], + use_variant --[[@as value -- please find a better approach]], "enum variant" ) end diff --git a/prelude.alc b/prelude.alc index ab9293f..bc894a3 100644 --- a/prelude.alc +++ b/prelude.alc @@ -55,25 +55,6 @@ let host-inferrable-term = unwrap(host-inferrable-term-wrap) let host-checkable-term = unwrap(host-checkable-term-wrap) let host-lua-error = unwrap(host-lua-error-wrap) -# TEMPORARY TEST: MOVE TO TEST FILE BEFORE FINALIZING PR - -let Result = lambda (T, E) - enum - Ok(x : T) - Err(e : E) - -let sqr = lambda (x) - x - -let switchtest = lambda (x : Result(host-number, host-number)) - switch x - Ok(x) -> x - Err(a) -> -1 - -switchtest(mk Ok(5)) -switchtest(mk Err(3)) - - let host-srel-type = lambda_implicit (U : type_(10, 0)) unwrap diff --git a/testlist.json b/testlist.json index c0e250e..b7e0447 100644 --- a/testlist.json +++ b/testlist.json @@ -12,6 +12,7 @@ "tests/implicit.alc": "success", "tests/operative-do.alc": "success", "tests/operative-tuple-desc.alc": "success", + "tests/switch-fail.alc": "termgen", "tests/switch-test.alc": "success", "tests/tuples.alc": "success" } \ No newline at end of file diff --git a/tests/switch-fail.alc b/tests/switch-fail.alc new file mode 100644 index 0000000..91b1933 --- /dev/null +++ b/tests/switch-fail.alc @@ -0,0 +1,12 @@ +let Result = lambda (T, E) + enum + Ok(x : T) + Err(e : E) + +let switchtest_ascribed = lambda (x : Result(host-number, host-number)) + switch x + Ok(x) -> x + Err(a) -> -1 + +switchtest_ascribed(mk Ok(5)) +switchtest_ascribed(mk Er(3)) \ No newline at end of file diff --git a/tests/switch-test.alc b/tests/switch-test.alc index 74fd8e0..be208c9 100644 --- a/tests/switch-test.alc +++ b/tests/switch-test.alc @@ -17,4 +17,13 @@ tuple-of-implicit let Result = lambda (T, E) enum Ok(x : T) - Err(e : E) \ No newline at end of file + Err(e : E) + +let switchtest_ascribed = lambda (x : Result(host-number, host-number)) + switch x + Ok(x) -> x * x + Err(a) -> a + +switchtest_ascribed(mk Ok(5)) +switchtest_ascribed(mk Err(3)) + \ No newline at end of file