use crate::records::type_function_instance_type::TypeFunctionInstanceType;
use crate::records::type_rehydration_visitor::TypeRehydrationVisitor;
use luaur_ast::records::allocator::Allocator;
use luaur_ast::records::ast_array::AstArray;
use luaur_ast::records::ast_name::AstName;
use luaur_ast::records::ast_type::AstType;
use luaur_ast::records::ast_type_reference::AstTypeReference;
use luaur_ast::records::location::Location;

impl TypeRehydrationVisitor {
    pub fn operator_call_18(&mut self, tfit: &TypeFunctionInstanceType) -> *mut AstType {
        let allocator = unsafe { &mut *self.allocator };
        let name = tfit.user_func_name.unwrap_or_else(|| {
            let func = unsafe { &*tfit.function.as_ptr() };
            AstName {
                value: func.name.as_ptr() as *const core::ffi::c_char,
            }
        });
        let reference = AstTypeReference::new(
            Location::default(),
            None,
            name,
            None,
            Location::default(),
            false,
            AstArray::default(),
        );
        allocator.alloc(reference) as *mut AstType
    }
}
