diff --git a/compiler/can/src/def.rs b/compiler/can/src/def.rs index e2e14aea6d..8f1cdd18c0 100644 --- a/compiler/can/src/def.rs +++ b/compiler/can/src/def.rs @@ -873,7 +873,15 @@ pub(crate) fn sort_can_defs_new( ); } }, - _ => todo!("{:?}", &def.loc_pattern.value), + _ => { + declarations.push_destructure_def( + def.loc_pattern, + def.loc_expr, + def.expr_var, + def.annotation, + def.pattern_vars.into_iter().collect(), + ); + } } } } diff --git a/compiler/can/src/expr.rs b/compiler/can/src/expr.rs index 4f193182e7..611e4b6083 100644 --- a/compiler/can/src/expr.rs +++ b/compiler/can/src/expr.rs @@ -2047,6 +2047,34 @@ impl Declarations { index } + /// Any def with a weird pattern + pub fn push_destructure_def( + &mut self, + loc_pattern: Loc, + loc_expr: Loc, + expr_var: Variable, + annotation: Option, + pattern_vars: VecMap, + ) -> usize { + let index = self.declarations.len(); + + let destruct_def = DestructureDef { + loc_pattern, + pattern_vars, + }; + + let destructure_def_index = Index::push_new(&mut self.destructs, destruct_def); + + self.declarations.push(DeclarationTag::Destructure(destructure_def_index)); + self.variables.push(expr_var); + self.symbols.push(Loc::at_zero(Symbol::ATTR_ATTR)); + self.annotations.push(annotation); + + self.expressions.push(loc_expr); + + index + } + pub fn push_def(&mut self, def: Def) { match def.loc_pattern.value { Pattern::Identifier(symbol) => match def.loc_expr.value { diff --git a/compiler/can/src/module.rs b/compiler/can/src/module.rs index ef04564a8c..11374f69f4 100644 --- a/compiler/can/src/module.rs +++ b/compiler/can/src/module.rs @@ -5,7 +5,7 @@ use crate::effect_module::HostedGeneratedFunctions; use crate::env::Env; use crate::expr::{ClosureData, Declarations, Expr, Output}; use crate::operator::desugar_def; -use crate::pattern::Pattern; +use crate::pattern::{BindingsFromPattern, Pattern}; use crate::scope::Scope; use bumpalo::Bump; use roc_collections::{MutMap, SendMap, VecSet}; @@ -526,7 +526,13 @@ pub fn canonicalize_module_defs<'a>( index += 1; } - Destructure(_) => todo!(), + Destructure(d_index) => { + let destruct_def = &declarations.destructs[d_index.index()]; + + for (symbol, _) in BindingsFromPattern::new(&destruct_def.loc_pattern) { + exposed_but_not_defined.remove(&symbol); + } + } MutualRecursion(_) => todo!(), } } diff --git a/compiler/collections/src/vec_map.rs b/compiler/collections/src/vec_map.rs index 8a38fcdb7b..8060bd008d 100644 --- a/compiler/collections/src/vec_map.rs +++ b/compiler/collections/src/vec_map.rs @@ -123,6 +123,15 @@ impl VecMap { } } +impl std::iter::FromIterator<(K, V)> for VecMap { + fn from_iter>(iter: T) -> Self { + let mut this = Self::default(); + this.extend(iter); + + this + } +} + impl Extend<(K, V)> for VecMap { #[inline(always)] fn extend>(&mut self, iter: T) {