mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-04 12:18:19 +00:00
Check record field suffixes in annotations
This commit is contained in:
parent
12c735644f
commit
ecc5fa57dd
4 changed files with 125 additions and 4 deletions
|
@ -101,7 +101,7 @@ mod test_reporting {
|
|||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
|
||||
let module_src = if src.starts_with("app") {
|
||||
let module_src = if src.starts_with("app") || src.starts_with("module") {
|
||||
maybe_save_parse_test_case(subdir, src, false);
|
||||
// this is already a module
|
||||
src.to_string()
|
||||
|
@ -15006,6 +15006,60 @@ All branches in an `if` must have the same type!
|
|||
"###
|
||||
);
|
||||
|
||||
test_report!(
|
||||
unsuffixed_fx_in_record_annotation,
|
||||
indoc!(
|
||||
r#"
|
||||
module [Fx]
|
||||
|
||||
Fx : {
|
||||
getLine: {} => Str
|
||||
}
|
||||
"#
|
||||
),
|
||||
@r"
|
||||
── MISSING EXCLAMATION in /code/proj/Main.roc ──────────────────────────────────
|
||||
|
||||
The type of this record field is an effectful function, but its name
|
||||
does not indicate so:
|
||||
|
||||
4│ getLine: {} => Str
|
||||
^^^^^^^^^^^^^^^^^^
|
||||
|
||||
Add an exclamation mark at the end, like:
|
||||
|
||||
{ readFile!: Str => Str }
|
||||
|
||||
This will help readers identify it as a source of effects.
|
||||
"
|
||||
);
|
||||
|
||||
test_report!(
|
||||
suffixed_pure_fn_in_record_annotation,
|
||||
indoc!(
|
||||
r#"
|
||||
module [Fx]
|
||||
|
||||
Fx : {
|
||||
getLine!: {} -> Str
|
||||
}
|
||||
"#
|
||||
),
|
||||
@r"
|
||||
── UNNECESSARY EXCLAMATION in /code/proj/Main.roc ──────────────────────────────
|
||||
|
||||
The type of this record field is a pure function, but its name
|
||||
suggests otherwise:
|
||||
|
||||
4│ getLine!: {} -> Str
|
||||
^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
The exclamation mark at the end is reserved for effectful functions.
|
||||
|
||||
Hint: Did you mean to use `=>` instead of `->`?
|
||||
"
|
||||
);
|
||||
|
||||
test_report!(
|
||||
unsuffixed_fx_arg,
|
||||
indoc!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue