add more helpful error for calling a decl that exists in a module (#6752)

* add more helpful error for calling a decl that exists in a module

* accord to suggestions

* make error more helpful
This commit is contained in:
pwygab
2022-10-23 00:41:31 +08:00
committed by GitHub
parent 4fdf5c663c
commit 3f555a6836
3 changed files with 42 additions and 0 deletions

View File

@ -546,6 +546,26 @@ impl EngineState {
None
}
pub fn which_module_has_decl(&self, name: &[u8]) -> Option<&[u8]> {
for (module_id, m) in self.modules.iter().enumerate() {
if m.has_decl(name) {
for overlay_frame in self.active_overlays(&[]).iter() {
let module_name = overlay_frame.modules.iter().find_map(|(key, &val)| {
if val == module_id {
Some(key)
} else {
None
}
});
if let Some(final_name) = module_name {
return Some(&final_name[..]);
}
}
}
}
None
}
pub fn find_overlay(&self, name: &[u8]) -> Option<OverlayId> {
self.scope.find_overlay(name)
}