use super::ProcessingScriptVisitor;
use leo_ast::{AstReconstructor, CallExpression, Expression, Location, Variant};
use leo_errors::TypeCheckerError;
impl AstReconstructor for ProcessingScriptVisitor<'_> {
type AdditionalInput = ();
type AdditionalOutput = ();
fn reconstruct_call(&mut self, input: CallExpression, _additional: &()) -> (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.absolute_path().to_vec()))
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.clone(), input.span))
}
}
(input.into(), Default::default())
}
}