luaur_analysis/methods/
constraint_generator_check_function_body.rs1use crate::enums::control_flow::ControlFlow;
2use crate::records::builtin_types::BuiltinTypes;
3use crate::records::constraint_generator::ConstraintGenerator;
4use crate::records::pack_subtype_constraint::PackSubtypeConstraint;
5use crate::type_aliases::constraint_v::ConstraintV;
6use crate::type_aliases::scope_ptr_type::ScopePtr;
7use luaur_ast::records::ast_expr_function::AstExprFunction;
8
9impl ConstraintGenerator {
10 pub fn check_function_body(&mut self, scope: &ScopePtr, fn_expr: &AstExprFunction) {
11 let cf = self
12 .visit_block_without_child_scope(scope.as_ref() as *const _ as *mut _, fn_expr.body);
13
14 if cf == ControlFlow::None {
15 let builtin_types = unsafe { &*self.builtin_types };
16 let sub_pack = builtin_types.emptyTypePack;
17 let super_pack = scope.return_type;
18
19 let constraint = PackSubtypeConstraint {
20 sub_pack,
21 super_pack,
22 returns: true,
23 };
24
25 self.add_constraint_scope_ptr_location_constraint_v(
26 scope,
27 fn_expr.base.base.location,
28 ConstraintV::PackSubtype(constraint),
29 );
30 }
31 }
32}