mirror of
https://github.com/roc-lang/roc.git
synced 2024-11-11 16:51:53 +03:00
commit
eee4cb1456
@ -4139,12 +4139,13 @@ fn sorted_field_symbols<'a>(
|
||||
let mut field_symbols_temp = Vec::with_capacity_in(args.len(), env.arena);
|
||||
|
||||
for (var, mut arg) in args.drain(..) {
|
||||
// Layout will unpack this unwrapped tack if it only has one (non-zero-sized) field
|
||||
// Layout will unpack this unwrapped tag if it only has one (non-zero-sized) field
|
||||
let layout = match layout_cache.from_var(env.arena, var, env.subs) {
|
||||
Ok(cached) => cached,
|
||||
Err(LayoutProblem::UnresolvedTypeVar(_)) => {
|
||||
// this argument has type `forall a. a`, which is isomorphic to
|
||||
// the empty type (Void, Never, the empty tag union `[]`)
|
||||
// Note it does not catch the use of `[]` currently.
|
||||
use roc_can::expr::Expr;
|
||||
arg.value = Expr::RuntimeError(RuntimeError::VoidValue);
|
||||
Layout::Struct(&[])
|
||||
|
@ -1539,7 +1539,9 @@ pub fn union_sorted_tags_help<'a>(
|
||||
}
|
||||
Err(LayoutProblem::UnresolvedTypeVar(_)) => {
|
||||
// If we encounter an unbound type var (e.g. `Ok *`)
|
||||
// then it's zero-sized; drop the argument.
|
||||
// then it's zero-sized; In the future we may drop this argument
|
||||
// completely, but for now we represent it with the empty struct
|
||||
layouts.push(Layout::Struct(&[]))
|
||||
}
|
||||
Err(LayoutProblem::Erroneous) => {
|
||||
// An erroneous type var will code gen to a runtime
|
||||
@ -1616,7 +1618,9 @@ pub fn union_sorted_tags_help<'a>(
|
||||
}
|
||||
Err(LayoutProblem::UnresolvedTypeVar(_)) => {
|
||||
// If we encounter an unbound type var (e.g. `Ok *`)
|
||||
// then it's zero-sized; drop the argument.
|
||||
// then it's zero-sized; In the future we may drop this argument
|
||||
// completely, but for now we represent it with the empty struct
|
||||
arg_layouts.push(Layout::Struct(&[]));
|
||||
}
|
||||
Err(LayoutProblem::Erroneous) => {
|
||||
// An erroneous type var will code gen to a runtime
|
||||
|
@ -98,3 +98,51 @@ fn result_map_err() {
|
||||
i64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn err_type_var() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
Result.map (Ok 3) (\x -> x + 1)
|
||||
|> Result.withDefault -1
|
||||
"#
|
||||
),
|
||||
4,
|
||||
i64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn err_type_var_annotation() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
ok : Result I64 *
|
||||
ok = Ok 3
|
||||
|
||||
Result.map ok (\x -> x + 1)
|
||||
|> Result.withDefault -1
|
||||
"#
|
||||
),
|
||||
4,
|
||||
i64
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn err_empty_tag_union() {
|
||||
assert_evals_to!(
|
||||
indoc!(
|
||||
r#"
|
||||
ok : Result I64 []
|
||||
ok = Ok 3
|
||||
|
||||
Result.map ok (\x -> x + 1)
|
||||
|> Result.withDefault -1
|
||||
"#
|
||||
),
|
||||
4,
|
||||
i64
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user