diff --git a/crates/compiler/load_internal/src/file.rs b/crates/compiler/load_internal/src/file.rs index 0531048b20..51706d12b5 100644 --- a/crates/compiler/load_internal/src/file.rs +++ b/crates/compiler/load_internal/src/file.rs @@ -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(); @@ -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)) diff --git a/crates/compiler/load_internal/tests/test_load.rs b/crates/compiler/load_internal/tests/test_load.rs index a514d0466d..d623f0854f 100644 --- a/crates/compiler/load_internal/tests/test_load.rs +++ b/crates/compiler/load_internal/tests/test_load.rs @@ -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()); +}