@@ -49,7 +49,7 @@ fn check_assign_stat(
4949 context,
5050 semantic_model,
5151 index_expr,
52- exprs. get ( idx) . map ( |expr| expr . clone ( ) ) ,
52+ exprs. get ( idx) . cloned ( ) ,
5353 value_types. get ( idx) ?. 0 . clone ( ) ,
5454 ) ;
5555 }
@@ -58,7 +58,7 @@ fn check_assign_stat(
5858 context,
5959 semantic_model,
6060 name_expr,
61- exprs. get ( idx) . map ( |expr| expr . clone ( ) ) ,
61+ exprs. get ( idx) . cloned ( ) ,
6262 value_types. get ( idx) ?. 0 . clone ( ) ,
6363 ) ;
6464 }
@@ -191,11 +191,11 @@ fn check_local_stat(
191191 & value_type,
192192 false ,
193193 ) ;
194- if let Some ( expr) = value_exprs. get ( idx) . map ( |expr| expr ) {
194+ if let Some ( expr) = value_exprs. get ( idx) {
195195 check_table_expr (
196196 context,
197197 semantic_model,
198- & expr,
198+ expr,
199199 Some ( & var_type) ,
200200 Some ( & value_type) ,
201201 ) ;
@@ -253,23 +253,21 @@ fn check_table_expr_content(
253253 . unwrap_or ( LuaType :: Any ) ;
254254
255255 // 位于的最后的 TableFieldValue 允许接受函数调用返回的多值, 而且返回的值必然会从下标 1 开始覆盖掉所有索引字段.
256- if field. is_value_field ( ) && idx == fields. len ( ) - 1 {
257- match & expr_type {
258- LuaType :: Variadic ( variadic) => {
259- if let Some ( result) = check_table_last_variadic_type (
260- context,
261- semantic_model,
262- table_type,
263- idx,
264- & variadic,
265- field. get_range ( ) ,
266- ) {
267- has_diagnostic = has_diagnostic || result;
268- }
269- continue ;
270- }
271- _ => { }
256+ if field. is_value_field ( )
257+ && idx == fields. len ( ) - 1
258+ && let LuaType :: Variadic ( variadic) = & expr_type
259+ {
260+ if let Some ( result) = check_table_last_variadic_type (
261+ context,
262+ semantic_model,
263+ table_type,
264+ idx,
265+ variadic,
266+ field. get_range ( ) ,
267+ ) {
268+ has_diagnostic = has_diagnostic || result;
272269 }
270+ continue ;
273271 }
274272
275273 let Some ( field_key) = field. get_field_key ( ) else {
@@ -278,29 +276,26 @@ fn check_table_expr_content(
278276 let Some ( member_key) = semantic_model. get_member_key ( & field_key) else {
279277 continue ;
280278 } ;
281- let source_type = match semantic_model. infer_member_type ( & table_type, & member_key) {
279+ let source_type = match semantic_model. infer_member_type ( table_type, & member_key) {
282280 Ok ( typ) => typ,
283281 Err ( _) => {
284282 continue ;
285283 }
286284 } ;
287285
288- if source_type. is_table ( ) || source_type. is_custom_type ( ) {
289- if let Some ( table_expr) = LuaTableExpr :: cast ( value_expr. syntax ( ) . clone ( ) ) {
290- // 检查子表
291- if let Some ( result) =
292- check_table_expr_content ( context, semantic_model, & source_type, & table_expr)
293- {
294- has_diagnostic = has_diagnostic || result;
295- }
296- continue ;
286+ if ( source_type. is_table ( ) || source_type. is_custom_type ( ) )
287+ && let Some ( table_expr) = LuaTableExpr :: cast ( value_expr. syntax ( ) . clone ( ) )
288+ {
289+ // 检查子表
290+ if let Some ( result) =
291+ check_table_expr_content ( context, semantic_model, & source_type, & table_expr)
292+ {
293+ has_diagnostic = has_diagnostic || result;
297294 }
295+ continue ;
298296 }
299297
300- let allow_nil = match table_type {
301- LuaType :: Array ( _) => true ,
302- _ => false ,
303- } ;
298+ let allow_nil = matches ! ( table_type, LuaType :: Array ( _) ) ;
304299
305300 if let Some ( result) = check_assign_type_mismatch (
306301 context,
@@ -329,7 +324,7 @@ fn check_table_last_variadic_type(
329324 for offset in idx..( idx + 10 ) {
330325 let member_key = LuaMemberKey :: Integer ( ( idx + offset) as i64 + 1 ) ;
331326 let source_type = semantic_model
332- . infer_member_type ( & table_type, & member_key)
327+ . infer_member_type ( table_type, & member_key)
333328 . ok ( ) ?;
334329 match source_type {
335330 LuaType :: Variadic ( source_variadic) => {
@@ -343,12 +338,11 @@ fn check_table_last_variadic_type(
343338 semantic_model,
344339 range,
345340 Some ( & source_type) ,
346- & expr_type,
341+ expr_type,
347342 false ,
348- ) {
349- if result {
350- return Some ( true ) ;
351- }
343+ ) && result
344+ {
345+ return Some ( true ) ;
352346 }
353347 }
354348 }
@@ -391,14 +385,14 @@ fn check_assign_type_mismatch(
391385 _ => { }
392386 }
393387
394- let result = semantic_model. type_check_detail ( & source_type, & value_type) ;
395- if ! result. is_ok ( ) {
388+ let result = semantic_model. type_check_detail ( source_type, value_type) ;
389+ if result. is_err ( ) {
396390 add_type_check_diagnostic (
397391 context,
398392 semantic_model,
399393 range,
400- & source_type,
401- & value_type,
394+ source_type,
395+ value_type,
402396 result,
403397 ) ;
404398 return Some ( true ) ;
@@ -416,7 +410,7 @@ fn add_type_check_diagnostic(
416410) {
417411 let db = semantic_model. get_db ( ) ;
418412 match result {
419- Ok ( _) => return ,
413+ Ok ( _) => ( ) ,
420414 Err ( reason) => {
421415 let reason_message = match reason {
422416 TypeCheckFailReason :: TypeNotMatchWithReason ( reason) => reason,
@@ -429,8 +423,8 @@ fn add_type_check_diagnostic(
429423 range,
430424 t ! (
431425 "Cannot assign `%{value}` to `%{source}`. %{reason}" ,
432- value = humanize_lint_type( db, & value_type) ,
433- source = humanize_lint_type( db, & source_type) ,
426+ value = humanize_lint_type( db, value_type) ,
427+ source = humanize_lint_type( db, source_type) ,
434428 reason = reason_message
435429 )
436430 . to_string ( ) ,
0 commit comments