Add unexpected fn params test case

This commit is contained in:
Agus Zubiaga 2024-08-27 17:24:13 -03:00
parent dd78b8e25b
commit a4f4d00ff0
No known key found for this signature in database
4 changed files with 58 additions and 15 deletions

View file

@ -771,14 +771,14 @@ mod cli_run {
#[test]
#[cfg_attr(windows, ignore)]
fn module_params_remove_from_errors() {
fn module_params_arity_mismatch() {
check_compile_error_with(
CMD_DEV,
&cli_testing_dir("/module_params/bad_types.roc"),
&cli_testing_dir("/module_params/arity_mismatch.roc"),
&[],
indoc!(
r#"
TOO MANY ARGS in tests/module_params/bad_types.roc
TOO MANY ARGS in tests/module_params/arity_mismatch.roc
The getUser function expects 1 argument, but it got 2 instead:
@ -788,7 +788,7 @@ mod cli_run {
Are there any missing commas? Or missing parentheses?
TOO MANY ARGS in tests/module_params/bad_types.roc
TOO MANY ARGS in tests/module_params/arity_mismatch.roc
This value is not a function, but it was given 1 argument:
@ -798,7 +798,7 @@ mod cli_run {
Are there any missing commas? Or missing parentheses?
TOO FEW ARGS in tests/module_params/bad_types.roc
TOO FEW ARGS in tests/module_params/arity_mismatch.roc
The getPostComment function expects 2 arguments, but it got only 1:
@ -815,6 +815,37 @@ mod cli_run {
);
}
#[test]
#[cfg_attr(windows, ignore)]
fn module_params_unexpected_fn() {
check_compile_error_with(
CMD_DEV,
&cli_testing_dir("/module_params/unexpected_fn.roc"),
&[],
indoc!(
r#"
TYPE MISMATCH in tests/module_params/unexpected_fn.roc
This argument to this string interpolation has an unexpected type:
11 $(Api.getPost)
^^^^^^^^^^^
The argument is an anonymous function of type:
U32 -> Str
But this string interpolation needs its argument to be:
Str
1 error and 0 warnings found in <ignored for test> ms."#
),
)
}
#[test]
#[cfg_attr(windows, ignore)]
fn transitive_expects() {

View file

@ -0,0 +1,12 @@
app [main] {
pf: platform "../fixtures/multi-dep-str/platform/main.roc",
}
import Api { appId: "one", protocol: https }
https = \url -> "https://$(url)"
main =
"""
$(Api.getPost)
"""

View file

@ -91,26 +91,26 @@ fn remove_with_bad_expr_reason(
name: Some(name),
arity,
called_via: _,
} => {
if env.is_extended(name) {
debug_assert_ne!(0, *arity);
} if env.is_extended(name) => {
*arity -= 1;
debug_assert_ne!(0, *arity);
*arity -= 1;
drop_last_argument(found_type);
drop_last_argument(expected_type);
}
drop_last_argument(found_type);
drop_last_argument(expected_type);
}
Reason::FnCall { .. } => {}
Reason::FnArg {
name: _,
name: Some(name),
arg_index: _,
called_via: _,
} => {
todo!();
} if env.is_extended(name) => {
todo!()
}
Reason::FnArg { .. } => {}
// Irrelevant
Reason::TypedArg {
name: _,