diff --git a/src/constrain/expr.rs b/src/constrain/expr.rs index ad87d222cd..99b476ddcb 100644 --- a/src/constrain/expr.rs +++ b/src/constrain/expr.rs @@ -680,29 +680,42 @@ fn constrain_empty_record(region: Region, expected: Expected) -> Constrain /// Constrain top-level module declarations #[inline(always)] -pub fn constrain_decls(home: ModuleId, decls: &[Declaration]) -> Constraint { +pub fn constrain_decls( + home: ModuleId, + decls: &[Declaration], + aliases: SendMap, +) -> Constraint { let mut constraint = Constraint::SaveTheEnvironment; + for decl in decls.iter().rev() { // NOTE: rigids are empty because they are not shared between top-level definitions match decl { Declaration::Declare(def) => { - constraint = constrain_def( - &Env { - home, - rigids: ImMap::default(), - }, - def, - constraint, + constraint = exists_with_aliases( + aliases.clone(), + Vec::new(), + constrain_def( + &Env { + home, + rigids: ImMap::default(), + }, + def, + constraint, + ), ); } Declaration::DeclareRec(defs) => { - constraint = constrain_recursive_defs( - &Env { - home, - rigids: ImMap::default(), - }, - defs, - constraint, + constraint = exists_with_aliases( + aliases.clone(), + Vec::new(), + constrain_recursive_defs( + &Env { + home, + rigids: ImMap::default(), + }, + defs, + constraint, + ), ); } Declaration::InvalidCycle(_, _) => panic!("TODO handle invalid cycle"), diff --git a/src/constrain/module.rs b/src/constrain/module.rs index 0debecdade..4ac22b1103 100644 --- a/src/constrain/module.rs +++ b/src/constrain/module.rs @@ -12,8 +12,15 @@ use crate::types::{Alias, Constraint, LetConstraint, Type}; pub fn constrain_module( home: ModuleId, decls: &[Declaration], + aliases: &MutMap, ) -> Constraint { - constrain_decls(home, &decls) + let mut send_aliases = SendMap::default(); + + for (symbol, alias) in aliases { + send_aliases.insert(*symbol, alias.clone()); + } + + constrain_decls(home, decls, send_aliases) } #[derive(Debug, Clone)] diff --git a/src/load/mod.rs b/src/load/mod.rs index 7be3f9cb7f..70b5073550 100644 --- a/src/load/mod.rs +++ b/src/load/mod.rs @@ -1014,7 +1014,7 @@ fn parse_and_constrain( problems, .. }) => { - let constraint = constrain_module(module_id, &declarations); + let constraint = constrain_module(module_id, &declarations, &aliases); let module = Module { module_id, declarations,