mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 19:58:18 +00:00
Report effectful statement in pure function
This commit is contained in:
parent
fd2493ee51
commit
b62665e49e
3 changed files with 69 additions and 35 deletions
|
@ -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!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue