use super::ProcessingScriptVisitor;
use leo_ast::{AstReconstructor, CallExpression, Expression, Location, Variant};
use leo_errors::TypeCheckerError;
impl AstReconstructor for ProcessingScriptVisitor<'_> {
type AdditionalOutput = ();
fn reconstruct_call(&mut self, input: CallExpression) -> (Expression, Self::AdditionalOutput) {
if !matches!(self.current_variant, Variant::Script) {
let callee_program = input.program.unwrap_or(self.program_name);
let Some(func_symbol) =
self.state.symbol_table.lookup_function(Location::new(callee_program, input.function.name))
else {
panic!("Type checking should have prevented this.");
};
if matches!(func_symbol.function.variant, Variant::Script) {
self.state.handler.emit_err(TypeCheckerError::non_script_calls_script(input.function, input.span))
}
}
(input.into(), Default::default())
}
}