Report effectful statement in pure function

This commit is contained in:
Agus Zubiaga 2024-10-16 19:05:26 -03:00
parent fd2493ee51
commit b62665e49e
No known key found for this signature in database
3 changed files with 69 additions and 35 deletions

View file

@ -14716,7 +14716,7 @@ All branches in an `if` must have the same type!
10 name = Effect.getLine! {}
^^^^^^^^^^^^^^^^^^
However, the type of the enclosing function indicates it must be pure:
However, the type of the enclosing function requires that it's pure:
8 getCheer : Str -> Str
^^^^^^^^^^
@ -14728,6 +14728,43 @@ All branches in an `if` must have the same type!
"###
);
test_report!(
fx_fn_annotated_as_pure_stmt,
indoc!(
r#"
app [main!] { pf: platform "../../../../../examples/cli/effects-platform/main.roc" }
import pf.Effect
main! = \{} ->
trim "hello "
trim : Str -> Str
trim = \msg ->
Effect.putLine! "Trimming $(msg)"
Str.trim msg
"#
),
@r###"
EFFECT IN PURE FUNCTION in /code/proj/Main.roc
This expression calls an effectful function:
10 Effect.putLine! "Trimming $(msg)"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
However, the type of the enclosing function requires that it's pure:
8 trim : Str -> Str
^^^^^^^^^^
Tip: Replace `->` with `=>` to annotate it as effectful.
You can still run the program with this error, which can be helpful
when you're debugging.
"###
);
test_report!(
nested_function_def_fx_no_bang,
indoc!(