mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-27 05:49:08 +00:00
Fix package module resolution in inline imports
We were still passing `ModuleIds` from `load` to `can`, but now that imports can appear in any scope, we don't know which package an unqualified module name belongs to from the top level. We now pass `PackageModuleIds` instead and keep a Map of `ModuleName` to `ModuleId` in `Scope`. This also allow us to import multiple modules with the same name from different packages as long as a unique alias is provided.
This commit is contained in:
parent
842a256907
commit
1f347f6ca1
13 changed files with 398 additions and 309 deletions
|
@ -13,7 +13,7 @@ use roc_collections::{MutMap, SendMap, VecMap, VecSet};
|
|||
use roc_error_macros::internal_error;
|
||||
use roc_module::ident::Ident;
|
||||
use roc_module::ident::Lowercase;
|
||||
use roc_module::symbol::{IdentIds, IdentIdsByModule, ModuleId, ModuleIds, Symbol};
|
||||
use roc_module::symbol::{IdentIds, IdentIdsByModule, ModuleId, PackageModuleIds, Symbol};
|
||||
use roc_parse::ast::{Defs, TypeAnnotation};
|
||||
use roc_parse::header::HeaderType;
|
||||
use roc_parse::pattern::PatternType;
|
||||
|
@ -275,7 +275,7 @@ pub fn canonicalize_module_defs<'a>(
|
|||
home: ModuleId,
|
||||
module_path: &str,
|
||||
src: &'a str,
|
||||
module_ids: &'a ModuleIds,
|
||||
qualified_module_ids: &'a PackageModuleIds<'a>,
|
||||
exposed_ident_ids: IdentIds,
|
||||
dep_idents: &'a IdentIdsByModule,
|
||||
aliases: MutMap<Symbol, Alias>,
|
||||
|
@ -284,10 +284,20 @@ pub fn canonicalize_module_defs<'a>(
|
|||
exposed_symbols: VecSet<Symbol>,
|
||||
symbols_from_requires: &[(Loc<Symbol>, Loc<TypeAnnotation<'a>>)],
|
||||
var_store: &mut VarStore,
|
||||
opt_shorthand: Option<&'a str>,
|
||||
) -> ModuleOutput {
|
||||
let mut can_exposed_imports = MutMap::default();
|
||||
let mut scope = Scope::new(home, exposed_ident_ids, imported_abilities_state);
|
||||
let mut env = Env::new(arena, home, dep_idents, module_ids);
|
||||
let mut scope = Scope::new(
|
||||
home,
|
||||
qualified_module_ids
|
||||
.get_name(home)
|
||||
.expect("home module not found")
|
||||
.as_inner()
|
||||
.to_owned(),
|
||||
exposed_ident_ids,
|
||||
imported_abilities_state,
|
||||
);
|
||||
let mut env = Env::new(arena, home, dep_idents, qualified_module_ids, opt_shorthand);
|
||||
|
||||
for (name, alias) in aliases.into_iter() {
|
||||
scope.add_alias(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue