diff --git a/compiler/can/src/scope.rs b/compiler/can/src/scope.rs index 3d83f8f87a..25e10274d3 100644 --- a/compiler/can/src/scope.rs +++ b/compiler/can/src/scope.rs @@ -430,33 +430,19 @@ impl ScopedIdentIds { } } - fn get_symbol(&self, ident: &Ident) -> Option { - self.ident_ids - .ident_strs() - .zip(self.in_scope.iter()) - .find_map(|((ident_id, string), keep)| { - if *keep && string == ident.as_str() { - Some(Symbol::new(self.home, ident_id)) - } else { - None - } - }) - } - fn has_in_scope(&self, ident: &Ident) -> Option<(Symbol, Region)> { - self.ident_ids - .ident_strs() - .zip(self.in_scope.iter()) - .find_map(|((ident_id, string), keep)| { - if *keep && string == ident.as_str() { - Some(( + for index in self.in_scope.iter_ones() { + if let Some((ident_id, string)) = self.ident_ids.get_name_at_index(index) { + if string == ident.as_str() { + return Some(( Symbol::new(self.home, ident_id), self.regions[ident_id.index()], - )) - } else { - None + )); } - }) + } + } + + None } fn idents_in_scope(&self) -> impl Iterator + '_ { diff --git a/compiler/module/src/symbol.rs b/compiler/module/src/symbol.rs index 462d44a8e4..3e0fe96d77 100644 --- a/compiler/module/src/symbol.rs +++ b/compiler/module/src/symbol.rs @@ -584,6 +584,12 @@ impl IdentIds { self.interner.try_get(id.0 as usize) } + pub fn get_name_at_index(&self, index: usize) -> Option<(IdentId, &str)> { + self.interner + .try_get(index) + .map(|v| (IdentId(index as u32), v)) + } + pub fn get_name_str_res(&self, ident_id: IdentId) -> ModuleResult<&str> { self.get_name(ident_id).with_context(|| IdentIdNotFound { ident_id,