@@ -187,8 +187,14 @@ pub struct SignatureInfo {
187187 pub method_name : Ident ,
188188 pub receiver_type : ReceiverType ,
189189 pub param_idents : Vec < Ident > ,
190+ /// Parameter types *without* receiver.
190191 pub param_types : Vec < venial:: TypeExpr > ,
191192 pub return_type : TokenStream ,
193+
194+ /// `(original index, new type)` only for changed parameters; empty if no changes.
195+ ///
196+ /// Index points into original venial tokens (i.e. takes into account potential receiver params).
197+ pub modified_param_types : Vec < ( usize , venial:: TypeExpr ) > ,
192198}
193199
194200impl SignatureInfo {
@@ -199,6 +205,7 @@ impl SignatureInfo {
199205 param_idents : vec ! [ ] ,
200206 param_types : vec ! [ ] ,
201207 return_type : quote ! { ( ) } ,
208+ modified_param_types : vec ! [ ] ,
202209 }
203210 }
204211
@@ -359,7 +366,8 @@ pub(crate) fn into_signature_info(
359366 } ;
360367
361368 let mut next_unnamed_index = 0 ;
362- for ( arg, _) in signature. params . inner {
369+ let mut modified_param_types = vec ! [ ] ;
370+ for ( index, ( arg, _) ) in signature. params . inner . into_iter ( ) . enumerate ( ) {
363371 match arg {
364372 venial:: FnParam :: Receiver ( recv) => {
365373 if receiver_type == ReceiverType :: GdSelf {
@@ -377,8 +385,17 @@ pub(crate) fn into_signature_info(
377385 }
378386 venial:: FnParam :: Typed ( arg) => {
379387 let ident = maybe_rename_parameter ( arg. name , & mut next_unnamed_index) ;
380- let ty = venial:: TypeExpr {
381- tokens : map_self_to_class_name ( arg. ty . tokens , class_name) ,
388+ let ty = match maybe_change_parameter_type ( arg. ty , & method_name, index) {
389+ // Parameter type was modified.
390+ Ok ( ty) => {
391+ modified_param_types. push ( ( index, ty. clone ( ) ) ) ;
392+ ty
393+ }
394+
395+ // Not an error, just unchanged.
396+ Err ( ty) => venial:: TypeExpr {
397+ tokens : map_self_to_class_name ( ty. tokens , class_name) ,
398+ } ,
382399 } ;
383400
384401 param_types. push ( ty) ;
@@ -393,6 +410,28 @@ pub(crate) fn into_signature_info(
393410 param_idents,
394411 param_types,
395412 return_type : ret_type,
413+ modified_param_types,
414+ }
415+ }
416+
417+ /// If `f32` is used for a delta parameter in a virtual process function, transparently use `f64` behind the scenes.
418+ fn maybe_change_parameter_type (
419+ param_ty : venial:: TypeExpr ,
420+ method_name : & Ident ,
421+ param_index : usize ,
422+ ) -> Result < venial:: TypeExpr , venial:: TypeExpr > {
423+ // A bit hackish, but TokenStream APIs are also notoriously annoying to work with. Not even PartialEq...
424+
425+ if param_index == 1
426+ && ( method_name == "process" || method_name == "physics_process" )
427+ && param_ty. tokens . len ( ) == 1
428+ && param_ty. tokens [ 0 ] . to_string ( ) == "f32"
429+ {
430+ Ok ( venial:: TypeExpr {
431+ tokens : vec ! [ TokenTree :: Ident ( ident( "f64" ) ) ] ,
432+ } )
433+ } else {
434+ Err ( param_ty)
396435 }
397436}
398437
0 commit comments