diff --git a/crates/cli/tests/cli_run.rs b/crates/cli/tests/cli_run.rs index 36bfe778e03..1544a888873 100644 --- a/crates/cli/tests/cli_run.rs +++ b/crates/cli/tests/cli_run.rs @@ -903,6 +903,25 @@ mod cli_run { ); } + #[test] + #[cfg_attr(windows, ignore)] + fn module_params_pass_task() { + test_roc_app( + "crates/cli/tests/module_params", + "pass_task.roc", + &[], + &[], + &[], + indoc!( + r#" + Hi, Agus! + "# + ), + UseValgrind::No, + TestCliCommands::Run, + ); + } + #[test] #[cfg_attr(windows, ignore)] fn transitive_expects() { diff --git a/crates/cli/tests/module_params/Menu.roc b/crates/cli/tests/module_params/Menu.roc new file mode 100644 index 00000000000..e16090caf54 --- /dev/null +++ b/crates/cli/tests/module_params/Menu.roc @@ -0,0 +1,7 @@ +module { echo } -> [menu] + +menu = \name -> + indirect name + +indirect = \name -> + echo "Hi, $(name)!" diff --git a/crates/cli/tests/module_params/pass_task.roc b/crates/cli/tests/module_params/pass_task.roc new file mode 100644 index 00000000000..7140af55e88 --- /dev/null +++ b/crates/cli/tests/module_params/pass_task.roc @@ -0,0 +1,7 @@ +app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.15.0/SlwdbJ-3GR7uBWQo6zlmYWNYOxnvo8r6YABXD-45UOw.tar.br" } + +import pf.Stdout +import Menu { echo: Stdout.line } + +main = + Menu.menu "Agus" diff --git a/crates/compiler/lower_params/src/lower.rs b/crates/compiler/lower_params/src/lower.rs index 89b3e1b8f64..43f312ce733 100644 --- a/crates/compiler/lower_params/src/lower.rs +++ b/crates/compiler/lower_params/src/lower.rs @@ -6,7 +6,7 @@ use roc_can::{ Expr::{self, *}, }, module::ModuleParams, - pattern::Pattern, + pattern::{Pattern, RecordDestruct}, }; use roc_collections::VecMap; use roc_module::symbol::{IdentId, IdentIds, ModuleId, Symbol}; @@ -184,14 +184,14 @@ impl<'a> LowerParams<'a> { } } } - Var(symbol, _var) => { + Var(symbol, var) => { if let Some((params, arity)) = self.params_extended_home_symbol(&symbol) { if arity == 0 { // Calling the result of a top-level value def in the current module fun.1.value = self.call_value_def_with_params( symbol, - params.whole_var, + var, params.whole_symbol, params.whole_var, ); @@ -410,11 +410,33 @@ impl<'a> LowerParams<'a> { fn home_params_argument(&mut self) -> Option<(Variable, AnnotatedMark, Loc)> { match &self.home_params { Some(module_params) => { - let new_var = self.var_store.fresh(); + let destructs: Vec> = module_params + .destructs + .iter() + .map(|destructure| { + destructure.map(|d| RecordDestruct { + symbol: d.symbol, + var: self.var_store.fresh(), + label: d.label.clone(), + typ: d.typ.clone(), + }) + }) + .collect(); + + let record_pattern = Pattern::RecordDestructure { + whole_var: module_params.record_var, + ext_var: module_params.record_ext_var, + destructs, + }; + let loc_record_pattern = Loc::at(module_params.region, record_pattern); + let as_pattern = + Pattern::As(Box::new(loc_record_pattern), module_params.whole_symbol); + let loc_pattern = Loc::at(module_params.region, as_pattern); + Some(( - new_var, + self.var_store.fresh(), AnnotatedMark::new(self.var_store), - module_params.pattern(), + loc_pattern, )) } None => None,