Unify import params on copied variable

This commit is contained in:
Agus Zubiaga 2024-11-05 18:10:01 -03:00
parent 544a5dcfec
commit 625a5425f4
No known key found for this signature in database
4 changed files with 42 additions and 2 deletions

View file

@ -922,6 +922,21 @@ mod cli_run {
);
}
#[test]
#[cfg_attr(windows, ignore)]
fn module_params_different_types() {
test_roc_app(
"crates/cli/tests/module_params",
"different_types.roc",
&["42"],
&[],
&[],
"Write something:\n42\n",
UseValgrind::No,
TestCliCommands::Run,
);
}
#[test]
#[cfg_attr(windows, ignore)]
fn module_params_multiline_pattern() {

View file

@ -0,0 +1,3 @@
module { passed } -> [exposed]
exposed = passed

View file

@ -0,0 +1,14 @@
app [main] {
cli: platform "https://github.com/roc-lang/basic-cli/releases/download/0.15.0/SlwdbJ-3GR7uBWQo6zlmYWNYOxnvo8r6YABXD-45UOw.tar.br",
}
import cli.Stdout
import cli.Stdin
import Alias { passed: Stdin.line } as In
import Alias { passed: Stdout.line } as Out
main =
Out.exposed! "Write something:"
input = In.exposed!
Out.exposed! input

View file

@ -1403,7 +1403,7 @@ fn solve(
}
ImportParams(opt_provided, module_id, region) => {
match (module_params_vars.get(module_id), opt_provided) {
(Some(expected), Some(provided)) => {
(Some(expected_og), Some(provided)) => {
let actual = either_type_index_to_var(
env,
rank,
@ -1415,10 +1415,18 @@ fn solve(
*provided,
);
let expected = {
// Similar to Lookup, we need to unify on a copy of the module params variable
// Otherwise, this import might make it less general than it really is
let mut solve_env = env.as_solve_env();
let solve_env = &mut solve_env;
deep_copy_var_in(solve_env, rank, *expected_og, solve_env.arena)
};
match unify(
&mut env.uenv(),
actual,
*expected,
expected,
UnificationMode::EQ,
Polarity::OF_VALUE,
) {