fix final list test

This commit is contained in:
Folkert 2021-05-14 01:02:16 +02:00
parent 1ee1a8114b
commit d25b1dc549
4 changed files with 36 additions and 26 deletions

View file

@ -144,12 +144,10 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
); );
// sub or (-) : Num a, Num a -> Num a // sub or (-) : Num a, Num a -> Num a
add_type!( add_top_level_function_type!(
Symbol::NUM_SUB, Symbol::NUM_SUB,
top_level_function( vec![num_type(flex(TVAR1)), num_type(flex(TVAR1))],
vec![num_type(flex(TVAR1)), num_type(flex(TVAR1))], Box::new(num_type(flex(TVAR1))),
Box::new(num_type(flex(TVAR1))),
),
); );
// subWrap : Int range, Int range -> Int range // subWrap : Int range, Int range -> Int range
@ -391,12 +389,10 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
); );
// mod : Int a, Int a -> Result (Int a) [ DivByZero ]* // mod : Int a, Int a -> Result (Int a) [ DivByZero ]*
add_type!( add_top_level_function_type!(
Symbol::NUM_MOD_INT, Symbol::NUM_MOD_INT,
top_level_function( vec![int_type(flex(TVAR1)), int_type(flex(TVAR1))],
vec![int_type(flex(TVAR1)), int_type(flex(TVAR1))], Box::new(result_type(int_type(flex(TVAR1)), div_by_zero.clone())),
Box::new(result_type(int_type(flex(TVAR1)), div_by_zero.clone())),
),
); );
// isMultipleOf : Int a, Int a -> Bool // isMultipleOf : Int a, Int a -> Bool
@ -850,9 +846,11 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
}); });
// keepErrs: List before, (before -> Result * after) -> List after // keepErrs: List before, (before -> Result * after) -> List after
add_type!(Symbol::LIST_KEEP_ERRS, { {
let_tvars! { star, cvar, before, after}; let_tvars! { star, cvar, before, after};
top_level_function(
add_top_level_function_type!(
Symbol::LIST_KEEP_ERRS,
vec![ vec![
list_type(flex(before)), list_type(flex(before)),
closure( closure(
@ -863,7 +861,7 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
], ],
Box::new(list_type(flex(after))), Box::new(list_type(flex(after))),
) )
}); };
// range : Int a, Int a -> List (Int a) // range : Int a, Int a -> List (Int a)
add_type!(Symbol::LIST_RANGE, { add_type!(Symbol::LIST_RANGE, {
@ -910,11 +908,12 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
) )
}); });
// map3 : List a, List b, List c, (a, b, c -> d) -> List d {
add_type!(Symbol::LIST_MAP3, {
let_tvars! {a, b, c, d, cvar}; let_tvars! {a, b, c, d, cvar};
top_level_function( // map3 : List a, List b, List c, (a, b, c -> d) -> List d
add_top_level_function_type!(
Symbol::LIST_MAP3,
vec![ vec![
list_type(flex(a)), list_type(flex(a)),
list_type(flex(b)), list_type(flex(b)),
@ -923,7 +922,7 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
], ],
Box::new(list_type(flex(d))), Box::new(list_type(flex(d))),
) )
}); };
// append : List elem, elem -> List elem // append : List elem, elem -> List elem
add_type!( add_type!(
@ -1263,15 +1262,13 @@ pub fn types() -> MutMap<Symbol, (SolvedType, Region)> {
); );
// mapErr : Result a x, (x -> y) -> Result a x // mapErr : Result a x, (x -> y) -> Result a x
add_type!( add_top_level_function_type!(
Symbol::RESULT_MAP_ERR, Symbol::RESULT_MAP_ERR,
top_level_function( vec![
vec![ result_type(flex(TVAR1), flex(TVAR3)),
result_type(flex(TVAR1), flex(TVAR3)), closure(vec![flex(TVAR3)], TVAR4, Box::new(flex(TVAR2))),
closure(vec![flex(TVAR3)], TVAR4, Box::new(flex(TVAR2))), ],
], Box::new(result_type(flex(TVAR1), flex(TVAR2))),
Box::new(result_type(flex(TVAR1), flex(TVAR2))),
),
); );
// after : Result a err, (a -> Result b err) -> Result b err // after : Result a err, (a -> Result b err) -> Result b err

View file

@ -3069,6 +3069,8 @@ pub fn build_proc_header_new<'a, 'ctx, 'env>(
) -> FunctionValue<'ctx> { ) -> FunctionValue<'ctx> {
let layout = env.arena.alloc(layout).full(); let layout = env.arena.alloc(layout).full();
dbg!(symbol, layout);
build_proc_header(env, layout_ids, symbol, &layout, proc) build_proc_header(env, layout_ids, symbol, &layout, proc)
} }

View file

@ -7524,6 +7524,7 @@ fn lowlevel_match_on_lambda_set<'a, F>(
where where
F: Fn(Symbol, Symbol) -> Call<'a> + Copy, F: Fn(Symbol, Symbol) -> Call<'a> + Copy,
{ {
dbg!(lambda_set);
match dbg!(lambda_set.runtime_representation()) { match dbg!(lambda_set.runtime_representation()) {
Layout::Union(_) => { Layout::Union(_) => {
let closure_tag_id_symbol = env.unique_symbol(); let closure_tag_id_symbol = env.unique_symbol();

View file

@ -1807,10 +1807,20 @@ fn list_keep_errs() {
assert_evals_to!("List.keepErrs [] (\\x -> x)", 0, i64); assert_evals_to!("List.keepErrs [] (\\x -> x)", 0, i64);
assert_evals_to!("List.keepErrs [1,2] (\\x -> Err x)", &[1, 2], &[i64]); assert_evals_to!("List.keepErrs [1,2] (\\x -> Err x)", &[1, 2], &[i64]);
assert_evals_to!( assert_evals_to!(
"List.keepErrs [0,1,2] (\\x -> x % 0 |> Result.mapErr (\\_ -> 32))", indoc!(
r#"
mapErr = \result, f ->
when result is
Err e -> Err ( f e )
Ok v -> Ok v
List.keepErrs [0,1,2] (\x -> x % 0 |> mapErr (\_ -> 32))
"#
),
&[32, 32, 32], &[32, 32, 32],
&[i64] &[i64]
); );
assert_evals_to!("List.keepErrs [Ok 1, Err 2] (\\x -> x)", &[2], &[i64]); assert_evals_to!("List.keepErrs [Ok 1, Err 2] (\\x -> x)", &[2], &[i64]);
} }