Test that blame error reporting doesn't panic
@@ -1308,21 +1308,32 @@ Assume(#alwaysTrue, false)
);
// Check that error reporting correctly handle type paths with List elements inside
- let err = eval_string("%deepSeq% ([{a = [1]}] | List {a: List Str}) false").unwrap_err();
- match err {
- Error::EvalError(EvalError::BlameError(l, _)) => {
+ fn eval_err(s: &str) -> (Error, Program) {
+ let src = Cursor::new(s);
+
+ let mut p = Program::new_from_source(src, "<test>")
+ .expect(&format!("unexpected IO error while parsing string {}", s));
+ (p.eval().unwrap_err(), p)
+ }
+
+ let (err, mut p) = eval_err("%deepSeq% ([{a = [1]}] | List {a: List Str}) false");
+ match &err {
+ Error::EvalError(EvalError::BlameError(ref l, _)) => {
assert_matches!(l.path.as_slice(), [Elem::List, Elem::Field(id), Elem::List] if &id.to_string() == "a")
}
err => panic!("expected blame error, got {:?}", err),
}
+ // Check that reporting doesn't panic
+ p.report(err);
- let err = eval_string("(%elemAt% (({foo = [(fun x => \"a\")]} | {foo: List (forall a. a -> Num)}).foo) 0) false").unwrap_err();
- match err {
- Error::EvalError(EvalError::BlameError(l, _)) => {
+ let (err, mut p) = eval_err("(%elemAt% (({foo = [(fun x => \"a\")]} | {foo: List (forall a. a -> Num)}).foo) 0) false");
+ match &err {
+ Error::EvalError(EvalError::BlameError(ref l, _)) => {
assert_matches!(l.path.as_slice(), [Elem::Field(id), Elem::List, Elem::Codomain] if &id.to_string() == "foo")
}
err => panic!("expected blame error, got {:?}", err),
}
+ p.report(err);
}
#[test]
