luaur_analysis/methods/
constraint_generator_check_pack_constraint_generator.rs1use crate::records::constraint_generator::ConstraintGenerator;
2use crate::records::inference_pack::InferencePack;
3use crate::type_aliases::scope_ptr_constraint_generator::ScopePtr;
4use crate::type_aliases::type_id::TypeId;
5use alloc::vec::Vec;
6use luaur_ast::records::ast_array::AstArray;
7use luaur_ast::records::ast_expr::AstExpr;
8
9impl ConstraintGenerator {
10 pub fn check_pack_scope_ptr_ast_array_ast_expr_vector_optional_type_id(
11 &mut self,
12 scope: &ScopePtr,
13 exprs: AstArray<*mut AstExpr>,
14 expected_types: &Vec<Option<TypeId>>,
15 ) -> InferencePack {
16 let mut head: Vec<TypeId> = Vec::new();
17 let mut tail: Option<crate::type_aliases::type_pack_id::TypePackId> = None;
18
19 for i in 0..exprs.size {
20 let expr: *mut AstExpr = unsafe { *exprs.data.add(i) };
21 if i < exprs.size - 1 {
22 let mut expected_type: Option<TypeId> = None;
23 if i < expected_types.len() {
24 expected_type = expected_types[i];
25 }
26 head.push(
27 self.check_scope_ptr_ast_expr_optional_type_id(scope, expr, expected_type)
28 .ty,
29 );
30 } else {
31 let mut expected_tail_types: Vec<Option<TypeId>> = Vec::new();
32 if i < expected_types.len() {
33 expected_tail_types.extend_from_slice(&expected_types[i..]);
34 }
35 tail = Some(
36 self.check_pack_scope_ptr_ast_expr_vector_optional_type_id_bool(
37 scope,
38 expr,
39 &expected_tail_types,
40 true,
41 )
42 .tp,
43 );
44 }
45 }
46
47 InferencePack {
48 tp: self.add_type_pack(head, tail),
49 refinements: Vec::new(),
50 }
51 }
52}