Improve error interface
This commit is contained in:
parent
45384fb394
commit
3cbd3bbf3c
@ -229,7 +229,7 @@ impl Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_type_check_error(&self, other: &Error) -> bool {
|
pub fn is_error(&self, other: &Error) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Error::AtSourcePosition { error, .. } => error.as_ref() == other,
|
Error::AtSourcePosition { error, .. } => error.as_ref() == other,
|
||||||
_ => self == other,
|
_ => self == other,
|
||||||
|
@ -40,7 +40,7 @@ mod assignment {
|
|||||||
",
|
",
|
||||||
);
|
);
|
||||||
|
|
||||||
assert!(result.unwrap_err().is_type_check_error(&Error::TypeCheck {
|
assert!(result.unwrap_err().is_error(&Error::TypeCheck {
|
||||||
expected: Type::String,
|
expected: Type::String,
|
||||||
actual: Type::Integer
|
actual: Type::Integer
|
||||||
}))
|
}))
|
||||||
@ -172,7 +172,7 @@ mod value {
|
|||||||
fn map_type_errors() {
|
fn map_type_errors() {
|
||||||
assert!(interpret("{ foo <bool> = 'bar' }")
|
assert!(interpret("{ foo <bool> = 'bar' }")
|
||||||
.unwrap_err()
|
.unwrap_err()
|
||||||
.is_type_check_error(&Error::TypeCheck {
|
.is_error(&Error::TypeCheck {
|
||||||
expected: Type::Boolean,
|
expected: Type::Boolean,
|
||||||
actual: Type::String
|
actual: Type::String
|
||||||
}))
|
}))
|
||||||
@ -435,7 +435,7 @@ mod type_definition {
|
|||||||
fn simple_type_check() {
|
fn simple_type_check() {
|
||||||
let result = interpret("x <bool> = 1");
|
let result = interpret("x <bool> = 1");
|
||||||
|
|
||||||
assert!(result.unwrap_err().is_type_check_error(&Error::TypeCheck {
|
assert!(result.unwrap_err().is_error(&Error::TypeCheck {
|
||||||
expected: Type::Boolean,
|
expected: Type::Boolean,
|
||||||
actual: Type::Integer
|
actual: Type::Integer
|
||||||
}));
|
}));
|
||||||
@ -468,7 +468,7 @@ mod type_definition {
|
|||||||
",
|
",
|
||||||
);
|
);
|
||||||
|
|
||||||
assert!(result.unwrap_err().is_type_check_error(&Error::TypeCheck {
|
assert!(result.unwrap_err().is_error(&Error::TypeCheck {
|
||||||
expected: Type::Function {
|
expected: Type::Function {
|
||||||
parameter_types: vec![],
|
parameter_types: vec![],
|
||||||
return_type: Box::new(Type::Boolean),
|
return_type: Box::new(Type::Boolean),
|
||||||
|
Loading…
Reference in New Issue
Block a user