@@ -303,6 +303,15 @@ def visit_ListComp(self, node):
303
303
finally :
304
304
self .env_stack .pop ()
305
305
306
+ def visit_Call (self , node ):
307
+ node = self .generic_visit (node )
308
+ node = asttyped .CallT (type = types .TVar (),
309
+ func = node .func , args = node .args , keywords = node .keywords ,
310
+ starargs = node .starargs , kwargs = node .kwargs ,
311
+ star_loc = node .star_loc , dstar_loc = node .dstar_loc ,
312
+ begin_loc = node .begin_loc , end_loc = node .end_loc , loc = node .loc )
313
+ return node
314
+
306
315
def visit_Lambda (self , node ):
307
316
extractor = LocalExtractor (env_stack = self .env_stack , engine = self .engine )
308
317
extractor .visit (node )
@@ -337,7 +346,6 @@ def visit_unsupported(self, node):
337
346
self .engine .process (diag )
338
347
339
348
# expr
340
- visit_Call = visit_unsupported
341
349
visit_Dict = visit_unsupported
342
350
visit_DictComp = visit_unsupported
343
351
visit_Ellipsis = visit_unsupported
@@ -707,6 +715,79 @@ def visit_comprehension(self, node):
707
715
self .generic_visit (node )
708
716
self ._unify_collection (element = node .target , collection = node .iter )
709
717
718
+ def visit_CallT (self , node ):
719
+ self .generic_visit (node )
720
+
721
+ for (sigil_loc , vararg ) in ((node .star_loc , node .starargs ),
722
+ (node .dstar_loc , node .kwargs )):
723
+ if vararg :
724
+ diag = diagnostic .Diagnostic ("error" ,
725
+ "variadic arguments are not supported" , {},
726
+ sigil_loc , [vararg .loc ])
727
+ self .engine .process (diag )
728
+ return
729
+
730
+ if types .is_var (node .func .type ):
731
+ return # not enough info yet
732
+ elif not types .is_function (node .func .type ):
733
+ diag = diagnostic .Diagnostic ("error" ,
734
+ "cannot call this expression of type {type}" ,
735
+ {"type" : types .TypePrinter ().name (node .func .type )},
736
+ node .func .loc , [])
737
+ self .engine .process (diag )
738
+ return
739
+
740
+ typ = node .func .type .find ()
741
+ passed_args = set ()
742
+
743
+ if len (node .args ) > typ .arity ():
744
+ note = diagnostic .Diagnostic ("note" ,
745
+ "extraneous argument(s)" , {},
746
+ node .args [typ .arity ()].loc .join (node .args [- 1 ].loc ))
747
+ diag = diagnostic .Diagnostic ("error" ,
748
+ "this function of type {type} accepts at most {num} arguments" ,
749
+ {"type" : types .TypePrinter ().name (node .func .type ),
750
+ "num" : typ .arity ()},
751
+ node .func .loc , [], [note ])
752
+ self .engine .process (diag )
753
+ return
754
+
755
+ for actualarg , (formalname , formaltyp ) in \
756
+ zip (node .args , list (typ .args .items ()) + list (typ .optargs .items ())):
757
+ self ._unify (actualarg .type , formaltyp ,
758
+ actualarg .loc , None )
759
+ passed_args .add (formalname )
760
+
761
+ for keyword in node .keywords :
762
+ if keyword .arg in passed_args :
763
+ diag = diagnostic .Diagnostic ("error" ,
764
+ "the argument '{name}' is already passed" ,
765
+ {"name" : keyword .arg },
766
+ keyword .arg_loc )
767
+ self .engine .process (diag )
768
+ return
769
+
770
+ if keyword .arg in typ .args :
771
+ self ._unify (keyword .value .type , typ .args [keyword .arg ],
772
+ keyword .value .loc , None )
773
+ elif keyword .arg in typ .optargs :
774
+ self ._unify (keyword .value .type , typ .optargs [keyword .arg ],
775
+ keyword .value .loc , None )
776
+ passed_args .add (keyword .arg )
777
+
778
+ for formalname in typ .args :
779
+ if formalname not in passed_args :
780
+ note = diagnostic .Diagnostic ("note" ,
781
+ "the called function is of type {type}" ,
782
+ {"type" : types .TypePrinter ().name (node .func .type )},
783
+ node .func .loc )
784
+ diag = diagnostic .Diagnostic ("error" ,
785
+ "mandatory argument '{name}' is not passed" ,
786
+ {"name" : formalname },
787
+ node .begin_loc .join (node .end_loc ), [], [note ])
788
+ self .engine .process (diag )
789
+ return
790
+
710
791
def visit_LambdaT (self , node ):
711
792
self .generic_visit (node )
712
793
signature_type = self ._type_from_arguments (node .args , node .body .type )
@@ -818,7 +899,7 @@ def extract_args(arg_nodes):
818
899
return OrderedDict (args )
819
900
820
901
return types .TFunction (extract_args (node .args [:len (node .args ) - len (node .defaults )]),
821
- extract_args (node .args [len (node .defaults ):]),
902
+ extract_args (node .args [len (node .args ) - len ( node . defaults ):]),
822
903
ret )
823
904
824
905
def visit_arguments (self , node ):
0 commit comments