use super::ProcessingScriptVisitor;
use leo_ast::{CallExpression, Expression, ExpressionReconstructor, Location, Variant};
use leo_errors::TypeCheckerError;
impl ExpressionReconstructor for ProcessingScriptVisitor<'_> {
type AdditionalOutput = ();
fn reconstruct_call(&mut self, input: CallExpression) -> (Expression, Self::AdditionalOutput) {
if !matches!(self.current_variant, Variant::Script) {
let Expression::Identifier(ident) = &input.function else {
panic!("Parsing guarantees that a function name is always an identifier.");
};
let callee_program = input.program.unwrap_or(self.program_name);
let Some(func_symbol) = self.state.symbol_table.lookup_function(Location::new(callee_program, ident.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(ident, input.span))
}
}
(input.into(), Default::default())
}
}