leo_ast/interpreter_value/
util.rs1use leo_errors::{InterpreterHalt, Result};
18use leo_span::Span;
19
20#[macro_export]
21macro_rules! tc_fail2 {
22    () => {
23        panic!("type checker failure")
24    };
25}
26
27#[macro_export]
28macro_rules! halt_no_span2 {
29    ($($x:tt)*) => {
30        return Err(InterpreterHalt::new(format!($($x)*)).into())
31    }
32}
33
34#[macro_export]
35macro_rules! halt2 {
36    ($span: expr) => {
37        return Err(InterpreterHalt::new_spanned(String::new(), $span).into())
38
39    };
40
41    ($span: expr, $($x:tt)*) => {
42        return Err(InterpreterHalt::new_spanned(format!($($x)*), $span).into())
43    };
44}
45
46#[macro_export]
47macro_rules! fail2 {
48    ($span: expr) => {
49        InterpreterHalt::new_spanned(String::new(), $span).into()
50
51    };
52
53    ($span: expr, $($x:tt)*) => {
54        InterpreterHalt::new_spanned(format!($($x)*), $span).into()
55    };
56}
57
58pub trait ExpectTc {
59    type T;
60    fn expect_tc(self, span: Span) -> Result<Self::T>;
61}
62
63impl<T> ExpectTc for Option<T> {
64    type T = T;
65
66    fn expect_tc(self, span: Span) -> Result<Self::T> {
67        match self {
68            Some(t) => Ok(t),
69            None => Err(InterpreterHalt::new_spanned("type failure".into(), span).into()),
70        }
71    }
72}
73
74impl<T, U: std::fmt::Debug> ExpectTc for Result<T, U> {
75    type T = T;
76
77    fn expect_tc(self, span: Span) -> Result<Self::T> {
78        self.map_err(|_e| InterpreterHalt::new_spanned("type failure".into(), span).into())
79    }
80}