Skip to content

Commit b0d1d16

Browse files
authored
Merge pull request #7412 from gamebox/issue-7407
#7407: Register package dependent packages
2 parents f6794cb + d0ec7e2 commit b0d1d16

File tree

2 files changed

+62
-3
lines changed

2 files changed

+62
-3
lines changed

crates/compiler/load_internal/src/file.rs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1317,8 +1317,13 @@ fn handle_root_type<'a>(
13171317

13181318
use HeaderType::*;
13191319

1320+
let use_main = match header_type {
1321+
Package { .. } | App { .. } | Platform { .. } => true,
1322+
Module { .. } | Builtin { .. } | Hosted { .. } => false,
1323+
};
1324+
13201325
match header_type {
1321-
Module { .. } | Builtin { .. } | Hosted { .. } => {
1326+
Module { .. } | Builtin { .. } | Hosted { .. } | Package { .. } => {
13221327
let main_path = opt_main_path.or_else(|| find_main_roc_recursively(src_dir));
13231328

13241329
let cache_dir = roc_cache_dir.as_persistent_path();
@@ -1340,9 +1345,15 @@ fn handle_root_type<'a>(
13401345
header_output.msg = Msg::Many(messages);
13411346
}
13421347

1343-
Ok((header_output, RootType::Module { main_path }))
1348+
let root_type = if use_main {
1349+
RootType::Main
1350+
} else {
1351+
RootType::Module { main_path }
1352+
};
1353+
1354+
Ok((header_output, root_type))
13441355
}
1345-
App { .. } | Package { .. } | Platform { .. } => Ok((header_output, RootType::Main)),
1356+
App { .. } | Platform { .. } => Ok((header_output, RootType::Main)),
13461357
}
13471358
} else {
13481359
Ok((header_output, RootType::Main))

crates/compiler/load_internal/tests/test_load.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2131,3 +2131,51 @@ fn roc_file_no_extension() {
21312131

21322132
assert_eq!(err, expected, "\n{}", err);
21332133
}
2134+
2135+
#[test]
2136+
fn roc_package_depends_on_other_package() {
2137+
let modules = vec![
2138+
(
2139+
"main",
2140+
indoc!(
2141+
r#"
2142+
package [Module] { other: "other/main.roc" }
2143+
"#
2144+
),
2145+
),
2146+
(
2147+
"Module.roc",
2148+
indoc!(
2149+
r#"
2150+
module [foo]
2151+
2152+
import other.OtherMod
2153+
2154+
foo = OtherMod.say "hello"
2155+
"#
2156+
),
2157+
),
2158+
(
2159+
"other/main.roc",
2160+
indoc!(
2161+
r#"
2162+
package [OtherMod] {}
2163+
"#
2164+
),
2165+
),
2166+
(
2167+
"other/OtherMod.roc",
2168+
indoc!(
2169+
r#"
2170+
module [say]
2171+
2172+
say = \msg -> "$(msg), world!"
2173+
"#
2174+
),
2175+
),
2176+
];
2177+
2178+
let result = multiple_modules("roc_package_depends_on_other_package", modules);
2179+
2180+
assert!(result.is_ok());
2181+
}

0 commit comments

Comments
 (0)