Refactor Binder to use Diagnostics
The Binder and its helper functions have been updated to accept and propagate a `Diagnostics` struct. This allows for better error reporting during the binding phase, enabling the compiler to continue processing even after encountering errors and collect all issues before halting. The `BoundKind::Error` node and `StaticType::Error` are introduced as "poison" nodes/types. These nodes indicate that an error occurred during compilation, preventing further valid processing of that specific AST fragment but allowing the compiler to continue with other parts of the code. The `Parser` has also been updated to return a `Diagnostics` struct, enabling it to report errors during the initial parsing stage while still attempting to build a partial AST. This adheres to the same error recovery strategy.
This commit is contained in:
+4
-1
@@ -306,6 +306,8 @@ pub enum StaticType {
|
||||
Function(Box<Signature>),
|
||||
FunctionOverloads(Vec<Signature>),
|
||||
Object(&'static str),
|
||||
/// A diagnostic poison type, allowing type-checking to continue after an error.
|
||||
Error,
|
||||
}
|
||||
|
||||
impl fmt::Display for StaticType {
|
||||
@@ -361,6 +363,7 @@ impl fmt::Display for StaticType {
|
||||
write!(f, "overloads({} variants)", sigs.len())
|
||||
}
|
||||
StaticType::Object(name) => write!(f, "{}", name),
|
||||
StaticType::Error => write!(f, "<error>"),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -368,7 +371,7 @@ impl fmt::Display for StaticType {
|
||||
impl StaticType {
|
||||
/// Returns true if `other` can be assigned to a location of type `self`.
|
||||
pub fn is_assignable_from(&self, other: &StaticType) -> bool {
|
||||
if self == other || matches!(self, StaticType::Any) || matches!(other, StaticType::Any) {
|
||||
if self == other || matches!(self, StaticType::Any) || matches!(other, StaticType::Any) || matches!(self, StaticType::Error) || matches!(other, StaticType::Error) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user