Skip to content

Commit

Permalink
Finalize tests, make error not stupid.
Browse files Browse the repository at this point in the history
  • Loading branch information
ErikMcClure committed Jan 5, 2025
1 parent 7f42fc5 commit b6d3e86
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 21 deletions.
6 changes: 5 additions & 1 deletion evaluator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 0 additions & 19 deletions prelude.alc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions testlist.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
12 changes: 12 additions & 0 deletions tests/switch-fail.alc
Original file line number Diff line number Diff line change
@@ -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))
11 changes: 10 additions & 1 deletion tests/switch-test.alc
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,13 @@ tuple-of-implicit
let Result = lambda (T, E)
enum
Ok(x : T)
Err(e : E)
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))

0 comments on commit b6d3e86

Please sign in to comment.