diff --git a/nac3core/src/typecheck/type_inferencer/mod.rs b/nac3core/src/typecheck/type_inferencer/mod.rs index dde45d79..dc3e1a0d 100644 --- a/nac3core/src/typecheck/type_inferencer/mod.rs +++ b/nac3core/src/typecheck/type_inferencer/mod.rs @@ -586,15 +586,45 @@ impl<'a> Fold<()> for Inferencer<'a> { unreachable!("must be tobj") } } else { + let top_level_defs = &self.top_level.definitions.read(); + if !self.defined_identifiers.contains_key(id) { match self.function_data.resolver.get_symbol_type( self.unifier, - &self.top_level.definitions.read(), + top_level_defs, self.primitives, *id, ) { Ok(_) => { - self.defined_identifiers.insert(*id, IdentifierInfo::default()); + // Determine if the referenced id refers to a global symbol + let is_explicit = top_level_defs + .iter() + .map(|def| match *def.read() { + TopLevelDef::Class { name, .. } => (name, false), + TopLevelDef::Function { simple_name, .. } => { + (simple_name, false) + } + TopLevelDef::Variable { simple_name, .. } => { + (simple_name, true) + } + }) + .find(|(global, _)| global == id) + .map(|(_, has_explicit_prop)| has_explicit_prop); + + self.defined_identifiers.insert( + *id, + IdentifierInfo { + source: match is_explicit { + Some(true) => DeclarationSource::Global { + is_explicit: Some(false), + }, + Some(false) => { + DeclarationSource::Global { is_explicit: None } + } + None => DeclarationSource::Local, + }, + }, + ); } Err(e) => { return report_error(