Skip to content

Commit

Permalink
Merge pull request #7048 from roc-lang/fix-task-params-threading
Browse files Browse the repository at this point in the history
  • Loading branch information
agu-z authored Sep 2, 2024
2 parents a1c9273 + e4079cc commit 2679ba3
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 6 deletions.
19 changes: 19 additions & 0 deletions crates/cli/tests/cli_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
7 changes: 7 additions & 0 deletions crates/cli/tests/module_params/Menu.roc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module { echo } -> [menu]

menu = \name ->
indirect name

indirect = \name ->
echo "Hi, $(name)!"
7 changes: 7 additions & 0 deletions crates/cli/tests/module_params/pass_task.roc
Original file line number Diff line number Diff line change
@@ -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"
34 changes: 28 additions & 6 deletions crates/compiler/lower_params/src/lower.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
);
Expand Down Expand Up @@ -410,11 +410,33 @@ impl<'a> LowerParams<'a> {
fn home_params_argument(&mut self) -> Option<(Variable, AnnotatedMark, Loc<Pattern>)> {
match &self.home_params {
Some(module_params) => {
let new_var = self.var_store.fresh();
let destructs: Vec<Loc<RecordDestruct>> = 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,
Expand Down

0 comments on commit 2679ba3

Please sign in to comment.