@@ -28,39 +28,65 @@ fn check_call_expr(
2828) -> Option < ( ) > {
2929 let func = semantic_model. infer_call_expr_func ( call_expr. clone ( ) , None ) ?;
3030 let params = func. get_params ( ) ;
31- let args = call_expr. get_args_list ( ) ?. get_args ( ) . collect :: < Vec < _ > > ( ) ;
31+ let mut args = call_expr
32+ . get_args_list ( ) ?
33+ . get_args ( )
34+ . map ( |arg| Some ( arg) )
35+ . collect :: < Vec < _ > > ( ) ;
36+ let colon_call = call_expr. is_colon_call ( ) ;
37+ let colon_define = func. is_colon_define ( ) ;
38+ match ( colon_call, colon_define) {
39+ ( true , true ) | ( false , false ) => { }
40+ ( false , true ) => {
41+ if args. len ( ) > 0 {
42+ args. remove ( 0 ) ;
43+ }
44+ }
45+ ( true , false ) => {
46+ args. insert ( 0 , None ) ;
47+ }
48+ }
49+
3250 for ( idx, param) in params. iter ( ) . enumerate ( ) {
3351 if idx >= args. len ( ) {
3452 break ;
3553 }
3654
55+ let arg = & args[ idx] ;
56+ if arg. is_none ( ) {
57+ continue ;
58+ }
59+ let arg = arg. clone ( ) . unwrap ( ) ;
60+
3761 if param. 0 == "..." {
3862 if param. 1 . is_none ( ) {
3963 break ;
4064 }
4165
4266 let param_type = param. 1 . clone ( ) . unwrap ( ) ;
4367 for arg in args. iter ( ) . skip ( idx) {
44- let mut expr_type = semantic_model
45- . infer_expr ( arg. clone ( ) )
46- . unwrap_or ( LuaType :: Any ) ;
47- // treat unknown type as any
48- if expr_type. is_unknown ( ) {
49- expr_type = LuaType :: Any ;
50- }
68+ if let Some ( arg) = arg {
69+ let mut expr_type = semantic_model
70+ . infer_expr ( arg. clone ( ) )
71+ . unwrap_or ( LuaType :: Any ) ;
72+ // treat unknown type as any
73+ if expr_type. is_unknown ( ) {
74+ expr_type = LuaType :: Any ;
75+ }
5176
52- if !semantic_model. check_type_compact ( & param_type, & expr_type) {
53- let db = semantic_model. get_db ( ) ;
54- context. add_diagnostic (
55- DiagnosticCode :: ParamTypeNotMatch ,
56- arg. get_range ( ) ,
57- format ! (
58- "expected {} but founded {}" ,
59- humanize_type( db, & param_type) ,
60- humanize_type( db, & expr_type)
61- ) ,
62- None ,
63- ) ;
77+ if !semantic_model. check_type_compact ( & param_type, & expr_type) {
78+ let db = semantic_model. get_db ( ) ;
79+ context. add_diagnostic (
80+ DiagnosticCode :: ParamTypeNotMatch ,
81+ arg. get_range ( ) ,
82+ format ! (
83+ "expected {} but founded {}" ,
84+ humanize_type( db, & param_type) ,
85+ humanize_type( db, & expr_type)
86+ ) ,
87+ None ,
88+ ) ;
89+ }
6490 }
6591 }
6692 } else {
@@ -69,7 +95,6 @@ fn check_call_expr(
6995 }
7096
7197 let param_type = param. 1 . clone ( ) . unwrap ( ) ;
72- let arg = & args[ idx] ;
7398 let mut expr_type = semantic_model
7499 . infer_expr ( arg. clone ( ) )
75100 . unwrap_or ( LuaType :: Any ) ;
0 commit comments