@@ -129,12 +129,12 @@ pub fn instantiate_doc_function(
129129 } ;
130130 match origin_param_type {
131131 LuaType :: Variadic ( variadic) => match variadic. deref ( ) {
132- VariadicType :: Base ( base) => {
133- if let LuaType :: TplRef ( tpl) = base {
132+ VariadicType :: Base ( base) => match base {
133+ LuaType :: TplRef ( tpl) => {
134134 if tpl. is_variadic ( ) {
135135 if let Some ( generics) = substitutor. get_variadic ( tpl. get_tpl_id ( ) ) {
136136 for ( j, typ) in generics. iter ( ) . enumerate ( ) {
137- let param_name = format ! ( "args_ {}" , i + j) ;
137+ let param_name = format ! ( "var {}" , i + j) ;
138138 new_params. push ( ( param_name, Some ( typ. clone ( ) ) ) ) ;
139139 }
140140 }
@@ -149,7 +149,7 @@ pub fn instantiate_doc_function(
149149 }
150150 SubstitutorValue :: MultiTypes ( types) => {
151151 for ( i, typ) in types. iter ( ) . enumerate ( ) {
152- let param_name = format ! ( "args_ {}" , i) ;
152+ let param_name = format ! ( "var {}" , i) ;
153153 new_params. push ( ( param_name, Some ( typ. clone ( ) ) ) ) ;
154154 }
155155 }
@@ -164,22 +164,37 @@ pub fn instantiate_doc_function(
164164 }
165165 }
166166 }
167- }
167+ LuaType :: Generic ( generic) => {
168+ let new_type = instantiate_generic ( db, generic, substitutor) ;
169+ // 如果是 rest 参数且实例化后的类型是 tuple, 那么我们将展开 tuple
170+ if let LuaType :: Tuple ( tuple_type) = & new_type {
171+ let base_index = new_params. len ( ) ;
172+ for ( offset, tuple_element) in tuple_type. get_types ( ) . iter ( ) . enumerate ( )
173+ {
174+ let param_name = format ! ( "var{}" , base_index + offset) ;
175+ new_params. push ( ( param_name, Some ( tuple_element. clone ( ) ) ) ) ;
176+ }
177+ continue ;
178+ }
179+ new_params. push ( ( origin_param. 0 . clone ( ) , Some ( new_type) ) ) ;
180+ }
181+ _ => { }
182+ } ,
168183 VariadicType :: Multi ( _) => ( ) ,
169184 } ,
170185 _ => {
171186 let new_type = instantiate_type_generic ( db, origin_param_type, substitutor) ;
172187 // 如果是 rest 参数且实例化后的类型是 tuple, 那么我们将展开 tuple
173- if origin_param. 0 == "..." && tpl_func_params. len ( ) == i + 1 {
174- if let LuaType :: Tuple ( tuple_type) = & new_type {
175- let base_index = new_params. len ( ) ;
176- for ( offset, tuple_element) in tuple_type. get_types ( ) . iter ( ) . enumerate ( ) {
177- let param_name = format ! ( "args_ {}" , base_index + offset) ;
178- new_params. push ( ( param_name, Some ( tuple_element. clone ( ) ) ) ) ;
179- }
180- continue ;
181- }
182- }
188+ // if origin_param.0 == "..." && tpl_func_params.len() == i + 1 {
189+ // if let LuaType::Tuple(tuple_type) = &new_type {
190+ // let base_index = new_params.len();
191+ // for (offset, tuple_element) in tuple_type.get_types().iter().enumerate() {
192+ // let param_name = format!("var {}", base_index + offset);
193+ // new_params.push((param_name, Some(tuple_element.clone())));
194+ // }
195+ // continue;
196+ // }
197+ // }
183198 new_params. push ( ( origin_param. 0 . clone ( ) , Some ( new_type) ) ) ;
184199 }
185200 }
@@ -202,6 +217,9 @@ pub fn instantiate_doc_function(
202217 }
203218 }
204219 }
220+ // dbg!(&new_params);
221+ // dbg!(&inst_ret_type);
222+ // dbg!(&modified_substitutor);
205223
206224 LuaType :: DocFunction (
207225 LuaFunctionType :: new ( async_state, colon_define, new_params, inst_ret_type) . into ( ) ,
@@ -267,17 +285,17 @@ fn instantiate_generic(
267285 let mut new_params = Vec :: new ( ) ;
268286 for param in generic_params {
269287 let new_param = instantiate_type_generic ( db, param, substitutor) ;
270- if let LuaType :: Variadic ( variadic) = & new_param {
271- match variadic. deref ( ) {
272- VariadicType :: Base ( _) => { }
273- VariadicType :: Multi ( types) => {
274- for typ in types {
275- new_params. push ( typ. clone ( ) ) ;
276- }
277- continue ;
278- }
279- }
280- }
288+ // if let LuaType::Variadic(variadic) = &new_param {
289+ // match variadic.deref() {
290+ // VariadicType::Base(_) => {}
291+ // VariadicType::Multi(types) => {
292+ // for typ in types {
293+ // new_params.push(typ.clone());
294+ // }
295+ // continue;
296+ // }
297+ // }
298+ // }
281299 new_params. push ( new_param) ;
282300 }
283301
@@ -319,12 +337,14 @@ fn instantiate_tpl_ref(_: &DbIndex, tpl: &GenericTpl, substitutor: &TypeSubstitu
319337 // 泛型是否以`T...`定义(非使用), 以`T...`定义的泛型我们应该将其视为一个元组
320338 if tpl. is_variadic ( ) {
321339 if let Some ( generics) = substitutor. get_variadic ( tpl. get_tpl_id ( ) ) {
322- if generics. len ( ) == 1 {
323- return generics[ 0 ] . clone ( ) ;
324- } else {
325- return LuaType :: Tuple (
326- LuaTupleType :: new ( generics. clone ( ) , LuaTupleStatus :: DocResolve ) . into ( ) ,
327- ) ;
340+ match generics. len ( ) {
341+ 1 => return generics[ 0 ] . clone ( ) ,
342+ _ => {
343+ return LuaType :: Variadic ( VariadicType :: Multi ( generics. clone ( ) ) . into ( ) ) ;
344+ // return LuaType::Tuple(
345+ // LuaTupleType::new(generics.clone(), LuaTupleStatus::DocResolve).into(),
346+ // );
347+ }
328348 }
329349 } else {
330350 return LuaType :: Never ;
@@ -466,6 +486,9 @@ fn instantiate_conditional(
466486 // 记录右侧出现的每个 infer 名称对应的具体类型
467487 let mut infer_assignments: HashMap < String , LuaType > = HashMap :: new ( ) ;
468488 let mut condition_result: Option < bool > = None ;
489+ // dbg!(&conditional);
490+ // dbg!(&substitutor);
491+ // println!("substitutor: {:?}", substitutor);
469492
470493 // 仅当条件形如 T extends ... 时才尝试提前求值, 否则返回原始结构
471494 if let LuaType :: Call ( alias_call) = conditional. get_condition ( )
@@ -488,6 +511,8 @@ fn instantiate_conditional(
488511 }
489512 }
490513 }
514+ // dbg!(&left);
515+ // dbg!(&right);
491516
492517 // infer 必须位于条件语句中(right), 判断是否包含并收集
493518 if contains_conditional_infer ( & right)
@@ -774,9 +799,6 @@ fn instantiate_mapped_type(
774799 . type_constraint
775800 . as_ref ( )
776801 . map ( |ty| instantiate_type_generic ( db, ty, substitutor) ) ;
777- dbg ! ( & mapped) ;
778- dbg ! ( & substitutor) ;
779- dbg ! ( & constraint) ;
780802
781803 if let Some ( constraint) = constraint {
782804 let mut key_types = Vec :: new ( ) ;
0 commit comments