This commit is contained in:
2026-02-11 16:35:05 +01:00
parent ee279425f2
commit 4e2645e12d
13 changed files with 229 additions and 176 deletions
+32
View File
@@ -26,6 +26,11 @@ pub enum LoxError {
expected: String,
found: String,
},
Return {
source_slice: SourceSlice,
value: BaseValue,
return_label: String,
},
}
/// Configuration for error display formatting
@@ -84,6 +89,13 @@ impl LoxError {
} => {
format!("expected {}, found {}", expected, found)
}
LoxError::Return {
value,
return_label,
..
} => {
format!("return value: {} and label: {}", value, return_label)
}
}
}
@@ -94,6 +106,11 @@ impl LoxError {
LoxError::ParseError { source_slice, .. } => Some(source_slice.clone()),
LoxError::IoError { .. } => None,
LoxError::TypeMismatch { source_slice, .. } => Some(source_slice.clone()),
LoxError::Return {
value,
return_label,
..
} => None,
}
}
@@ -104,6 +121,7 @@ impl LoxError {
LoxError::ParseError { .. } => "parse error",
LoxError::IoError { .. } => "io error",
LoxError::TypeMismatch { .. } => "type error",
LoxError::Return { .. } => "return error",
}
}
@@ -396,6 +414,20 @@ impl fmt::Display for LoxError {
found
)
}
LoxError::Return {
value,
return_label,
source_slice,
} => {
write!(
f,
"Return error at {}:{}: value `{}`, label `{}`",
source_slice.start_position.line + 1,
source_slice.start_position.column + 1,
value,
return_label
)
}
}
}
}