Merge pull request #7038 from mulias/expr-dbg

Support `dbg` in expressions
This commit is contained in:
Anton-4 2024-09-02 13:30:32 +02:00 committed by GitHub
commit 02cf61f985
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
33 changed files with 1308 additions and 249 deletions

View file

@ -170,6 +170,7 @@ pub fn can_expr_with<'a>(
// rules multiple times unnecessarily.
let loc_expr = desugar::desugar_expr(
arena,
&mut var_store,
&loc_expr,
expr_str,
&mut None,

View file

@ -5760,28 +5760,6 @@ mod test_reporting {
"#
);
test_report!(
dbg_without_final_expression,
indoc!(
r"
dbg 42
"
),
@r#"
INDENT ENDS AFTER EXPRESSION in tmp/dbg_without_final_expression/Test.roc
I am partway through parsing a dbg statement, but I got stuck here:
4 dbg 42
^
I was expecting a final expression, like so
dbg 42
"done"
"#
);
test_report!(
expect_without_final_expression,
indoc!(
@ -14517,6 +14495,76 @@ All branches in an `if` must have the same type!
"
);
test_report!(
dbg_unapplied,
indoc!(
r"
1 + dbg + 2
"
),
@r"
UNAPPLIED DBG in /code/proj/Main.roc
This `dbg` doesn't have a value given to it:
4 1 + dbg + 2
^^^
`dbg` must be passed a value to print at the exact place it's used. `dbg`
can't be used as a value that's passed around, like functions can be -
it must be applied immediately!
TYPE MISMATCH in /code/proj/Main.roc
This 2nd argument to + has an unexpected type:
4 1 + dbg + 2
^^^
This `63` value is a:
{}
But + needs its 2nd argument to be:
Num *
"
);
test_report!(
dbg_overapplied,
indoc!(
r#"
1 + dbg "" "" + 2
"#
),
@r#"
OVERAPPLIED DBG in /code/proj/Main.roc
This `dbg` has too many values given to it:
4 1 + dbg "" "" + 2
^^^^^
`dbg` must be given exactly one value to print.
TYPE MISMATCH in /code/proj/Main.roc
This 2nd argument to + has an unexpected type:
4 1 + dbg "" "" + 2
^^^^^^^^^
This `63` value is a:
{}
But + needs its 2nd argument to be:
Num *
"#
);
// TODO: add the following tests after built-in Tasks are added
// https://github.com/roc-lang/roc/pull/6836