Skip to content

Commit

Permalink
Merge pull request #7412 from gamebox/issue-7407
Browse files Browse the repository at this point in the history
#7407: Register package dependent packages
  • Loading branch information
smores56 authored Dec 26, 2024
2 parents f6794cb + d0ec7e2 commit b0d1d16
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
17 changes: 14 additions & 3 deletions crates/compiler/load_internal/src/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1317,8 +1317,13 @@ fn handle_root_type<'a>(

use HeaderType::*;

let use_main = match header_type {
Package { .. } | App { .. } | Platform { .. } => true,
Module { .. } | Builtin { .. } | Hosted { .. } => false,
};

match header_type {
Module { .. } | Builtin { .. } | Hosted { .. } => {
Module { .. } | Builtin { .. } | Hosted { .. } | Package { .. } => {
let main_path = opt_main_path.or_else(|| find_main_roc_recursively(src_dir));

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

Ok((header_output, RootType::Module { main_path }))
let root_type = if use_main {
RootType::Main
} else {
RootType::Module { main_path }
};

Ok((header_output, root_type))
}
App { .. } | Package { .. } | Platform { .. } => Ok((header_output, RootType::Main)),
App { .. } | Platform { .. } => Ok((header_output, RootType::Main)),
}
} else {
Ok((header_output, RootType::Main))
Expand Down
48 changes: 48 additions & 0 deletions crates/compiler/load_internal/tests/test_load.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2131,3 +2131,51 @@ fn roc_file_no_extension() {

assert_eq!(err, expected, "\n{}", err);
}

#[test]
fn roc_package_depends_on_other_package() {
let modules = vec![
(
"main",
indoc!(
r#"
package [Module] { other: "other/main.roc" }
"#
),
),
(
"Module.roc",
indoc!(
r#"
module [foo]
import other.OtherMod
foo = OtherMod.say "hello"
"#
),
),
(
"other/main.roc",
indoc!(
r#"
package [OtherMod] {}
"#
),
),
(
"other/OtherMod.roc",
indoc!(
r#"
module [say]
say = \msg -> "$(msg), world!"
"#
),
),
];

let result = multiple_modules("roc_package_depends_on_other_package", modules);

assert!(result.is_ok());
}

0 comments on commit b0d1d16

Please sign in to comment.