@@ -14,12 +14,12 @@ macro_rules! count_tts {
1414
1515#[ macro_export]
1616macro_rules! type_check{
17-
18- ( $vm: ident, $arg: expr, $arg_count: expr, $arg_name: ident, $arg_type: expr) =>{
17+ ( $vm: ident, $args: ident, $arg_count: ident, $arg_name: ident, $arg_type: expr) =>{
1918// None indicates that we have no type requirement (i.e. we accept any type)
2019if let Some ( expected_type) = $arg_type{
21- if !$crate:: obj:: objtype:: isinstance( $arg, & expected_type) {
22- let arg_typ = $arg. typ( ) ;
20+ let arg =& $args. args[ $arg_count] ;
21+ if !$crate:: obj:: objtype:: isinstance( arg, & expected_type) {
22+ let arg_typ = arg. typ( ) ;
2323let expected_type_name = $vm. to_pystr( & expected_type) ?;
2424let actual_type = $vm. to_pystr( & arg_typ) ?;
2525return Err ( $vm. new_type_error( format!(
@@ -71,7 +71,7 @@ macro_rules! arg_check {
7171// check if the type matches. If not, return with error
7272// assign the arg to a variable
7373 $(
74- type_check!( $vm, & $args. args [ arg_count ] , arg_count, $arg_name, $arg_type) ;
74+ type_check!( $vm, $args, arg_count, $arg_name, $arg_type) ;
7575let $arg_name =& $args. args[ arg_count] ;
7676 #[ allow( unused_assignments) ]
7777{
@@ -83,21 +83,14 @@ macro_rules! arg_check {
8383// check if the type matches. If not, return with error
8484// assign the arg to a variable
8585 $(
86- let len = $args. args. len( ) ;
87- let klen = $args. kwargs. len( ) ;
88- let $optional_arg_name =if arg_count >= len &&( arg_count - len) < $args. kwargs. len( ) {
89- let idx = klen -( arg_count-len) -1 ;
90- type_check!( $vm, & $args. kwargs[ idx] . 1 , arg_count-len, $optional_arg_name, $optional_arg_type) ;
91- let kwarg =& $args. kwargs[ idx] ;
92- if & kwarg. 0 == stringify!( $optional_arg_name) {
93- #[ allow( unused_assignments) ]
94- {
95- arg_count +=1 ;
96- }
97- Some ( & kwarg. 1 )
98- } else{
99- None
86+ let $optional_arg_name =if arg_count < $args. args. len( ) {
87+ type_check!( $vm, $args, arg_count, $optional_arg_name, $optional_arg_type) ;
88+ let ret =Some ( & $args. args[ arg_count] ) ;
89+ #[ allow( unused_assignments) ]
90+ {
91+ arg_count +=1 ;
10092}
93+ ret
10194} else{
10295None
10396} ;