diff --git a/compiler/gen/tests/gen_primitives.rs b/compiler/gen/tests/gen_primitives.rs index b0dacec440..14e0981be3 100644 --- a/compiler/gen/tests/gen_primitives.rs +++ b/compiler/gen/tests/gen_primitives.rs @@ -1111,4 +1111,96 @@ mod gen_primitives { |_| 1 ); } + + #[test] + fn linked_list_len() { + assert_non_opt_evals_to!( + indoc!( + r#" + app Test provides [ main, len ] imports [] + + ConsList a : [ Cons a (ConsList a), Nil ] + + len : ConsList a -> Int + len = \list -> + when list is + Cons _ rest -> 1 + len rest + + Nil -> + 0 + + main : ConsList Int -> Int + main = len + "# + ), + 1, + i64, + |_| 1 + ); + } + + #[test] + fn linked_list_is_empty_1() { + assert_non_opt_evals_to!( + indoc!( + r#" + app Test provides [ main ] imports [] + + ConsList a : [ Cons a (ConsList a), Nil ] + + empty : ConsList a + empty = Nil + + isEmpty : ConsList a -> Bool + isEmpty = \list -> + when list is + Cons _ _ -> + False + + Nil -> + True + + main : Bool + main = + myList : ConsList Int + myList = empty + + isEmpty myList + "# + ), + true, + bool + ); + } + + #[test] + fn linked_list_is_empty_2() { + assert_non_opt_evals_to!( + indoc!( + r#" + app Test provides [ main ] imports [] + + ConsList a : [ Cons a (ConsList a), Nil ] + + # isEmpty : ConsList a -> Bool + isEmpty = \list -> + when list is + Cons _ _ -> + False + + Nil -> + True + + main : Bool + main = + myList : ConsList Int + myList = Cons 0x1 Nil + + isEmpty myList + "# + ), + false, + bool + ); + } } diff --git a/compiler/load/src/file.rs b/compiler/load/src/file.rs index 70876b1200..ad4b3c3b89 100644 --- a/compiler/load/src/file.rs +++ b/compiler/load/src/file.rs @@ -1690,6 +1690,9 @@ fn update<'a>( if state.dependencies.solved_all() && state.goal_phase == Phase::MakeSpecializations { debug_assert!(work.is_empty()); + + Proc::insert_refcount_operations(arena, &mut state.procedures); + // display the mono IR of the module, for debug purposes if roc_mono::ir::PRETTY_PRINT_IR_SYMBOLS { let procs_string = state @@ -1703,8 +1706,6 @@ fn update<'a>( println!("{}", result); } - Proc::insert_refcount_operations(arena, &mut state.procedures); - msg_tx .send(Msg::FinishedAllSpecialization { subs, diff --git a/examples/effect/Main.roc b/examples/effect/Main.roc index ecfaf3ae0f..687f0e4df2 100644 --- a/examples/effect/Main.roc +++ b/examples/effect/Main.roc @@ -1,9 +1,20 @@ -app Main provides [ main ] imports [ Effect ] +app Main provides [ main ] imports [ Effect, ConsList ] + +empty : ConsList.ConsList Int +empty = ConsList.empty main : Effect.Effect {} as Fx main = - Effect.always "Write a thing" - |> Effect.map (\line -> Str.concat line "!") - |> Effect.after (\line -> Effect.putLine line) - |> Effect.after (\{} -> Effect.getLine) - |> Effect.after (\line -> Effect.putLine line) + if ConsList.isEmpty empty then + Effect.putLine "Yay" + |> Effect.after (\{} -> Effect.getLine) + |> Effect.after (\line -> Effect.putLine line) + else + Effect.putLine "Nay" + + +# Effect.always "Write a thing" +# |> Effect.map (\line -> Str.concat line "!") +# |> Effect.after (\line -> Effect.putLine line) +# |> Effect.after (\{} -> Effect.getLine) +# |> Effect.after (\line -> Effect.putLine line)