diff --git a/crates/cli/tests/cli_run.rs b/crates/cli/tests/cli_run.rs index 1544a88887..a27aa457ab 100644 --- a/crates/cli/tests/cli_run.rs +++ b/crates/cli/tests/cli_run.rs @@ -922,6 +922,25 @@ mod cli_run { ); } + #[test] + #[cfg_attr(windows, ignore)] + fn module_params_multiline_pattern() { + test_roc_app( + "crates/cli/tests/module_params", + "multiline_params.roc", + &[], + &[], + &[], + indoc!( + r#" + hi + "# + ), + UseValgrind::No, + TestCliCommands::Dev, + ); + } + #[test] #[cfg_attr(windows, ignore)] fn transitive_expects() { diff --git a/crates/cli/tests/module_params/MultilineParams.roc b/crates/cli/tests/module_params/MultilineParams.roc new file mode 100644 index 0000000000..631b88473b --- /dev/null +++ b/crates/cli/tests/module_params/MultilineParams.roc @@ -0,0 +1,8 @@ +module { + sendHttpReq, + getEnvVar +} -> [hi] + +hi : Str +hi = + "hi" diff --git a/crates/cli/tests/module_params/multiline_params.roc b/crates/cli/tests/module_params/multiline_params.roc new file mode 100644 index 0000000000..531721c925 --- /dev/null +++ b/crates/cli/tests/module_params/multiline_params.roc @@ -0,0 +1,11 @@ +app [main] { + pf: platform "../fixtures/multi-dep-str/platform/main.roc", +} + +import MultilineParams { + sendHttpReq: \_ -> crash "todo", + getEnvVar: \_ -> crash "todo", +} + +main = + MultilineParams.hi \ No newline at end of file diff --git a/crates/compiler/can/src/desugar.rs b/crates/compiler/can/src/desugar.rs index 3ae037c4b0..1e253c6134 100644 --- a/crates/compiler/can/src/desugar.rs +++ b/crates/compiler/can/src/desugar.rs @@ -1187,17 +1187,7 @@ fn desugar_pattern<'a>(env: &mut Env<'a>, scope: &mut Scope, pattern: Pattern<'a Apply(tag, desugared_arg_patterns.into_bump_slice()) } RecordDestructure(field_patterns) => { - let mut allocated = Vec::with_capacity_in(field_patterns.len(), env.arena); - for field_pattern in field_patterns.iter() { - let value = desugar_pattern(env, scope, field_pattern.value); - allocated.push(Loc { - value, - region: field_pattern.region, - }); - } - let field_patterns = field_patterns.replace_items(allocated.into_bump_slice()); - - RecordDestructure(field_patterns) + RecordDestructure(desugar_record_destructures(env, scope, field_patterns)) } RequiredField(name, field_pattern) => { RequiredField(name, desugar_loc_pattern(env, scope, field_pattern)) @@ -1235,6 +1225,23 @@ fn desugar_pattern<'a>(env: &mut Env<'a>, scope: &mut Scope, pattern: Pattern<'a } } +pub fn desugar_record_destructures<'a>( + env: &mut Env<'a>, + scope: &mut Scope, + field_patterns: Collection<'a, Loc>>, +) -> Collection<'a, Loc>> { + let mut allocated = Vec::with_capacity_in(field_patterns.len(), env.arena); + for field_pattern in field_patterns.iter() { + let value = desugar_pattern(env, scope, field_pattern.value); + allocated.push(Loc { + value, + region: field_pattern.region, + }); + } + + field_patterns.replace_items(allocated.into_bump_slice()) +} + /// Desugars a `dbg expr` expression into a statement block that prints and returns the /// value produced by `expr`. Essentially: /// ( diff --git a/crates/compiler/can/src/module.rs b/crates/compiler/can/src/module.rs index 14dc2f827b..3a45b6ba91 100644 --- a/crates/compiler/can/src/module.rs +++ b/crates/compiler/can/src/module.rs @@ -3,6 +3,7 @@ use std::path::Path; use crate::abilities::{AbilitiesStore, ImplKey, PendingAbilitiesStore, ResolvedImpl}; use crate::annotation::{canonicalize_annotation, AnnotationFor}; use crate::def::{canonicalize_defs, report_unused_imports, Def}; +use crate::desugar::desugar_record_destructures; use crate::env::Env; use crate::expr::{ ClosureData, DbgLookup, Declarations, ExpectLookup, Expr, Output, PendingDerives, @@ -326,13 +327,16 @@ pub fn canonicalize_module_defs<'a>( before_arrow: _, after_arrow: _, }| { + let desugared_patterns = + desugar_record_destructures(&mut env, &mut scope, pattern.value); + let (destructs, _) = canonicalize_record_destructs( &mut env, var_store, &mut scope, &mut output, PatternType::ModuleParams, - &pattern.value, + &desugared_patterns, pattern.region, PermitShadows(false), ); diff --git a/crates/compiler/can/src/pattern.rs b/crates/compiler/can/src/pattern.rs index ddd6efda30..ffd097e3ae 100644 --- a/crates/compiler/can/src/pattern.rs +++ b/crates/compiler/can/src/pattern.rs @@ -914,7 +914,10 @@ pub fn canonicalize_record_destructs<'a>( } }; } - _ => unreachable!("Any other pattern should have given a parse error"), + _ => unreachable!( + "Any other pattern should have given a parse error: {:?}", + loc_pattern.value + ), } }