mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 13:29:12 +00:00
Treat untyped unsuffixed functions as pure
This commit is contained in:
parent
70fa4d036c
commit
af6fc6306f
5 changed files with 186 additions and 24 deletions
|
@ -15275,4 +15275,91 @@ All branches in an `if` must have the same type!
|
|||
Hint: Did you forget to run an effect? Is the type annotation wrong?
|
||||
"###
|
||||
);
|
||||
|
||||
test_report!(
|
||||
fx_passed_to_untyped_pure_hof,
|
||||
indoc!(
|
||||
r#"
|
||||
app [main!] { pf: platform "../../../../../examples/cli/effects-platform/main.roc" }
|
||||
|
||||
import pf.Effect
|
||||
|
||||
main! = \{} ->
|
||||
pureHigherOrder Effect.putLine! "hi"
|
||||
|
||||
pureHigherOrder = \f, x -> f x
|
||||
"#
|
||||
),
|
||||
@r###"
|
||||
── TYPE MISMATCH in /code/proj/Main.roc ────────────────────────────────────────
|
||||
|
||||
This 1st argument to `pureHigherOrder` has an unexpected type:
|
||||
|
||||
6│ pureHigherOrder Effect.putLine! "hi"
|
||||
^^^^^^^^^^^^^^^
|
||||
|
||||
This `Effect.putLine!` value is a:
|
||||
|
||||
Str => {}
|
||||
|
||||
But `pureHigherOrder` needs its 1st argument to be:
|
||||
|
||||
Str -> {}
|
||||
|
||||
── UNNECESSARY EXCLAMATION in /code/proj/Main.roc ──────────────────────────────
|
||||
|
||||
This function is pure, but its name suggests otherwise:
|
||||
|
||||
5│ main! = \{} ->
|
||||
^^^^^
|
||||
|
||||
The exclamation mark at the end is reserved for effectful functions.
|
||||
|
||||
Hint: Did you forget to run an effect? Is the type annotation wrong?
|
||||
"###
|
||||
);
|
||||
|
||||
test_report!(
|
||||
fx_passed_to_partially_inferred_pure_hof,
|
||||
indoc!(
|
||||
r#"
|
||||
app [main!] { pf: platform "../../../../../examples/cli/effects-platform/main.roc" }
|
||||
|
||||
import pf.Effect
|
||||
|
||||
main! = \{} ->
|
||||
pureHigherOrder Effect.putLine! "hi"
|
||||
|
||||
pureHigherOrder : _, _ -> _
|
||||
pureHigherOrder = \f, x -> f x
|
||||
"#
|
||||
),
|
||||
@r###"
|
||||
── TYPE MISMATCH in /code/proj/Main.roc ────────────────────────────────────────
|
||||
|
||||
This 1st argument to `pureHigherOrder` has an unexpected type:
|
||||
|
||||
6│ pureHigherOrder Effect.putLine! "hi"
|
||||
^^^^^^^^^^^^^^^
|
||||
|
||||
This `Effect.putLine!` value is a:
|
||||
|
||||
Str => {}
|
||||
|
||||
But `pureHigherOrder` needs its 1st argument to be:
|
||||
|
||||
Str -> {}
|
||||
|
||||
── UNNECESSARY EXCLAMATION in /code/proj/Main.roc ──────────────────────────────
|
||||
|
||||
This function is pure, but its name suggests otherwise:
|
||||
|
||||
5│ main! = \{} ->
|
||||
^^^^^
|
||||
|
||||
The exclamation mark at the end is reserved for effectful functions.
|
||||
|
||||
Hint: Did you forget to run an effect? Is the type annotation wrong?
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue