diff --git a/src/protocol/eval/error.rs b/src/protocol/eval/error.rs index 81128b445a5c36ed8cda7034b2ca9d2f99084a8e..488097f6357b6d5e67f9d2eb2fd3fa387a06c09d 100644 --- a/src/protocol/eval/error.rs +++ b/src/protocol/eval/error.rs @@ -10,7 +10,7 @@ use super::executor::*; /// Represents a stack frame recorded in an error #[derive(Debug)] pub struct EvalFrame { - pub line: u32, + pub line: Option, pub module_name: String, pub procedure: String, // function or component pub is_func: bool, @@ -24,10 +24,15 @@ impl fmt::Display for EvalFrame { "component" }; + let line_str = match self.line { + Some(line_number) => line_number.to_string(), + None => String::from("??"), + }; + if self.module_name.is_empty() { - write!(f, "{} {}:{}", func_or_comp, &self.procedure, self.line) + write!(f, "{} {}:{}", func_or_comp, &self.procedure, line_str) } else { - write!(f, "{} {}:{}:{}", func_or_comp, &self.module_name, &self.procedure, self.line) + write!(f, "{} {}:{}:{}", func_or_comp, &self.module_name, &self.procedure, line_str) } } } @@ -50,7 +55,7 @@ impl EvalError { for frame in prompt.frames.iter() { let definition = &heap[frame.definition]; let statement = &heap[frame.position]; - let statement_span = statement.span(); + let statement_span = statement.maybe_span(); // Lookup module name, if it has one let module = modules.iter().find(|m| m.root_id == definition.defined_in).unwrap(); @@ -62,7 +67,7 @@ impl EvalError { last_module_source = &module.source; frames.push(EvalFrame{ - line: statement_span.begin.line, + line: statement_span.map(|v| v.begin.line), module_name, procedure: definition.identifier.value.as_str().to_string(), is_func: definition.kind == ProcedureKind::Function,