Skip to main content

luaur_analysis/records/
magic_require.rs

1use crate::records::magic_function::MagicFunction;
2use crate::records::magic_function_call_context::MagicFunctionCallContext;
3use crate::records::scope::Scope;
4use crate::records::type_checker::TypeChecker;
5use crate::records::with_predicate::WithPredicate;
6use crate::type_aliases::type_pack_id::TypePackId;
7use luaur_ast::records::ast_expr_call::AstExprCall;
8
9#[derive(Debug, Clone)]
10pub struct MagicRequire {
11    pub(crate) base: MagicFunction,
12    pub(crate) handle_old_solver: fn(
13        &mut TypeChecker,
14        &std::sync::Arc<Scope>,
15        &AstExprCall,
16        WithPredicate<TypePackId>,
17    ) -> Option<WithPredicate<TypePackId>>,
18    pub(crate) infer: fn(&MagicFunctionCallContext) -> bool,
19}
20
21impl MagicRequire {
22    pub fn handle_old_solver(
23        &self,
24        context: &mut TypeChecker,
25        scope: &std::sync::Arc<Scope>,
26        call_site: &AstExprCall,
27        old_result: WithPredicate<TypePackId>,
28    ) -> Option<WithPredicate<TypePackId>> {
29        (self.handle_old_solver)(context, scope, call_site, old_result)
30    }
31
32    pub fn infer(&self, ctx: &MagicFunctionCallContext) -> bool {
33        (self.infer)(ctx)
34    }
35}