mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-30 15:21:12 +00:00
started using scope properly, improved error backtrace conversion
This commit is contained in:
parent
2158686a0a
commit
a272765fc7
19 changed files with 184 additions and 110 deletions
|
@ -1,5 +1,7 @@
|
|||
use snafu::{Backtrace, Snafu};
|
||||
|
||||
use crate::symbol::IdentId;
|
||||
|
||||
#[derive(Debug, Snafu)]
|
||||
#[snafu(visibility(pub))]
|
||||
pub enum ModuleError {
|
||||
|
@ -13,6 +15,16 @@ pub enum ModuleError {
|
|||
all_ident_ids: String,
|
||||
backtrace: Backtrace,
|
||||
},
|
||||
#[snafu(display(
|
||||
"IdentIdNotFound: I could not find IdentId {:?} in ident_ids {:?}.",
|
||||
ident_id,
|
||||
ident_ids_str
|
||||
))]
|
||||
IdentIdNotFound {
|
||||
ident_id: IdentId,
|
||||
ident_ids_str: String,
|
||||
backtrace: Backtrace,
|
||||
},
|
||||
}
|
||||
|
||||
pub type ModuleResult<T, E = ModuleError> = std::result::Result<T, E>;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
use crate::ident::{Ident, ModuleName};
|
||||
use crate::module_err::{ModuleIdNotFound, ModuleResult};
|
||||
use crate::module_err::{ModuleIdNotFound, IdentIdNotFound, ModuleResult};
|
||||
use roc_collections::all::{default_hasher, MutMap, SendMap};
|
||||
use roc_ident::IdentStr;
|
||||
use roc_region::all::Region;
|
||||
|
@ -264,6 +264,15 @@ impl Interns {
|
|||
all_ident_ids: format!("{:?}", self.all_ident_ids),
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_module_ident_ids_mut(&mut self, module_id: &ModuleId) -> ModuleResult<&mut IdentIds> {
|
||||
self.all_ident_ids
|
||||
.get_mut(module_id)
|
||||
.with_context(|| ModuleIdNotFound {
|
||||
module_id: format!("{:?}", module_id),
|
||||
all_ident_ids: "I could not return all_ident_ids here because of borrowing issues.",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(debug_assertions)]
|
||||
|
@ -634,6 +643,18 @@ impl IdentIds {
|
|||
pub fn get_name(&self, id: IdentId) -> Option<&Ident> {
|
||||
self.by_id.get(id.0 as usize)
|
||||
}
|
||||
|
||||
pub fn get_name_str_res(&self, ident_id: IdentId) -> ModuleResult<&str> {
|
||||
Ok(self
|
||||
.get_name(ident_id)
|
||||
.with_context(|| IdentIdNotFound {
|
||||
ident_id,
|
||||
ident_ids_str: format!("{:?}", self),
|
||||
})?
|
||||
.as_inline_str()
|
||||
.as_str()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// BUILTINS
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue