mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 19:58:18 +00:00
Merge pull request #4090 from roc-lang/i4084
Properly import builtin modules in platforms
This commit is contained in:
commit
f4e77a9e38
3 changed files with 58 additions and 8 deletions
|
@ -3911,14 +3911,21 @@ fn send_header_two<'a>(
|
|||
// Also build a list of imported_values_to_expose (like `bar` above.)
|
||||
for (qualified_module_name, exposed_idents, region) in imported.into_iter() {
|
||||
let cloned_module_name = qualified_module_name.module.clone();
|
||||
let pq_module_name = match qualified_module_name.opt_package {
|
||||
None => match opt_shorthand {
|
||||
Some(shorthand) => {
|
||||
PQModuleName::Qualified(shorthand, qualified_module_name.module)
|
||||
}
|
||||
None => PQModuleName::Unqualified(qualified_module_name.module),
|
||||
},
|
||||
Some(package) => PQModuleName::Qualified(package, cloned_module_name),
|
||||
let pq_module_name = if qualified_module_name.is_builtin() {
|
||||
// If this is a builtin, it must be unqualified, and we should *never* prefix it
|
||||
// with the package shorthand! The user intended to import the module as-is here.
|
||||
debug_assert!(qualified_module_name.opt_package.is_none());
|
||||
PQModuleName::Unqualified(qualified_module_name.module)
|
||||
} else {
|
||||
match qualified_module_name.opt_package {
|
||||
None => match opt_shorthand {
|
||||
Some(shorthand) => {
|
||||
PQModuleName::Qualified(shorthand, qualified_module_name.module)
|
||||
}
|
||||
None => PQModuleName::Unqualified(qualified_module_name.module),
|
||||
},
|
||||
Some(package) => PQModuleName::Qualified(package, cloned_module_name),
|
||||
}
|
||||
};
|
||||
|
||||
let module_id = module_ids.get_or_insert(&pq_module_name);
|
||||
|
|
|
@ -872,3 +872,40 @@ fn issue_2863_module_type_does_not_exist() {
|
|||
Ok(_) => unreachable!("we expect failure here"),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn import_builtin_in_platform_and_check_app() {
|
||||
let modules = vec![
|
||||
(
|
||||
"platform/main.roc",
|
||||
indoc!(
|
||||
r#"
|
||||
platform "testplatform"
|
||||
requires {} { main : Str }
|
||||
exposes []
|
||||
packages {}
|
||||
imports [Str]
|
||||
provides [mainForHost]
|
||||
|
||||
mainForHost : Str
|
||||
mainForHost = main
|
||||
"#
|
||||
),
|
||||
),
|
||||
(
|
||||
"Main",
|
||||
indoc!(
|
||||
r#"
|
||||
app "test"
|
||||
packages { pf: "platform/main.roc" }
|
||||
provides [main] to pf
|
||||
|
||||
main = ""
|
||||
"#
|
||||
),
|
||||
),
|
||||
];
|
||||
|
||||
let result = multiple_modules("issue_2863_module_type_does_not_exist", modules);
|
||||
assert!(result.is_ok(), "should check");
|
||||
}
|
||||
|
|
|
@ -796,6 +796,12 @@ macro_rules! define_builtins {
|
|||
)+
|
||||
num_modules: $total:literal
|
||||
} => {
|
||||
impl<'a> super::ident::QualifiedModuleName<'a> {
|
||||
pub fn is_builtin(&self) -> bool {
|
||||
self.opt_package.is_none() && ($($module_name == self.module.as_str() ||)+ false)
|
||||
}
|
||||
}
|
||||
|
||||
impl IdentIds {
|
||||
pub fn exposed_builtins(extra_capacity: usize) -> IdentIdsByModule {
|
||||
let mut exposed_idents_by_module = VecMap::with_capacity(extra_capacity + $total);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue