fix(runtime): resolve runtime errors against their logical module (B-08)
RuntimeError and CallFrame now carry a logical ModuleId and an origin (source/callsite). Errors are attributed at function/body boundaries so the innermost callee module wins; argument-binding errors and host/plugin/foreign boundaries are attributed to the caller callsite without fabricating a foreign stack. The CLI resolves (module_id, span) through LoadedProject::locate instead of indexing every span against the entry file. Unknown modules and out-of-range spans keep the module id and byte span but emit null line/file. Human output and frames now point at the correct file. Record the decision in ADR-0017 and supersede the ADR-0006 limitation. Add an end-to-end imported-module division-by-zero test.
This commit is contained in:
1 parent
6fed396d20
commit
509bdb1bf6
8 files changed
+390
-38
No files matched your search
@@ -63,6 +63,16 @@ impl FileDiagnostic {
|
||||
}
|
||||
}
|
||||
|
||||
/// A resolved source location inside a loaded file.
|
||||
pub struct LocatedSource<'a> {
|
||||
/// The owning file.
|
||||
pub file: &'a LoadedFile,
|
||||
/// 1-based line.
|
||||
pub line: usize,
|
||||
/// 1-based column.
|
||||
pub column: usize,
|
||||
}
|
||||
|
||||
/// A fully loaded project ready for checking or running.
|
||||
pub struct LoadedProject {
|
||||
/// Project root.
|
||||
@@ -92,6 +102,24 @@ impl LoadedProject {
|
||||
&self.files[&self.entry]
|
||||
}
|
||||
|
||||
/// Resolve a logical `(module_id, span)` location to a loaded file.
|
||||
///
|
||||
/// Returns `None` for an unknown module or an out-of-range span; callers
|
||||
/// must not guess or fall back to the entry file.
|
||||
pub fn locate(&self, module_id: &str, span: marqdo_span::Span) -> Option<LocatedSource<'_>> {
|
||||
let module = ModuleId::parse(module_id).ok()?;
|
||||
let file = self.files.get(&module)?;
|
||||
if span.start > span.end || span.end > file.source.len() {
|
||||
return None;
|
||||
}
|
||||
let position = marqdo_span::LineIndex::new(&file.source).line_col(span.start);
|
||||
Some(LocatedSource {
|
||||
file,
|
||||
line: position.line,
|
||||
column: position.column,
|
||||
})
|
||||
}
|
||||
|
||||
/// Resolve a physical path to its loaded or statically addressable module.
|
||||
pub fn module_id_for_path(&self, path: &Path) -> Option<ModuleId> {
|
||||
let canonical = path.canonicalize().ok()?;
|
||||
|
||||
Reference in new issue
Block a user