Test tag destructure suffixes

This commit is contained in:
Agus Zubiaga 2024-10-23 02:50:15 -03:00
parent 2c208f9389
commit a0783c3132
No known key found for this signature in database

View file

@ -15142,5 +15142,77 @@ All branches in an `if` must have the same type!
"###
);
test_report!(
unsuffixed_tag_fx_field,
indoc!(
r#"
app [main!] { pf: platform "../../../../../examples/cli/effects-platform/main.roc" }
import pf.Effect
main! = \{} ->
Tag get put = Tag Effect.getLine! Effect.putLine!
name = get {}
put "Hi, $(name)"
"#
),
@r###"
MISSING EXCLAMATION in /code/proj/Main.roc
This function is effectful, but its name does not indicate so:
6 Tag get put = Tag Effect.getLine! Effect.putLine!
^^^
Add an exclamation mark at the end, like:
get!
This will help readers identify it as a source of effects.
MISSING EXCLAMATION in /code/proj/Main.roc
This function is effectful, but its name does not indicate so:
6 Tag get put = Tag Effect.getLine! Effect.putLine!
^^^
Add an exclamation mark at the end, like:
put!
This will help readers identify it as a source of effects.
"###
);
test_report!(
suffixed_tag_pure_field,
indoc!(
r#"
app [main!] { pf: platform "../../../../../examples/cli/effects-platform/main.roc" }
import pf.Effect
main! = \{} ->
Tag msg trim! = Tag " hi " Str.trim
Effect.putLine! (trim! msg)
"#
),
@r###"
UNNECESSARY EXCLAMATION in /code/proj/Main.roc
This function is pure, but its name suggests otherwise:
6 Tag msg trim! = Tag " hi " Str.trim
^^^^^
The exclamation mark at the end is reserved for effectful functions.
Hint: Did you forget to run an effect? Is the type annotation wrong?
"###
);
// [purity-inference] TODO: check ! in records, tuples, tags, opaques, and arguments
}