@@ -9,7 +9,7 @@ use crate::class::{into_signature_info, make_virtual_callback, BeforeKind, Signa
9
9
use crate :: util:: ident;
10
10
use crate :: { util, ParseResult } ;
11
11
12
- use proc_macro2:: { Group , Ident , TokenStream } ;
12
+ use proc_macro2:: { Delimiter , Group , Ident , TokenStream } ;
13
13
use quote:: { quote, ToTokens } ;
14
14
15
15
/// Codegen for `#[godot_api] impl ISomething for MyType`.
@@ -479,21 +479,30 @@ fn handle_regular_virtual_fn<'a>(
479
479
480
480
// If there was a signature change (e.g. f32 -> f64 in process/physics_process), apply to new function tokens.
481
481
if !signature_info. modified_param_types . is_empty ( ) {
482
+ let mut param_name = None ;
483
+
482
484
let mut new_params = original_method. params . clone ( ) ;
483
485
for ( index, new_ty) in signature_info. modified_param_types . iter ( ) {
484
486
let venial:: FnParam :: Typed ( typed) = & mut new_params. inner [ * index] . 0 else {
485
- panic ! ( "Unexpected parameter type: {new_params:?}" ) ;
487
+ panic ! ( "unexpected parameter type: {new_params:?}" ) ;
486
488
} ;
487
489
488
490
typed. ty = new_ty. clone ( ) ;
491
+ param_name = Some ( typed. name . clone ( ) ) ;
489
492
}
490
493
491
- let body = original_method
492
- . body
493
- . clone ( )
494
- . expect ( "function must have a body" ) ;
494
+ let original_body = & original_method. body ;
495
+ let param_name = param_name. expect ( "parameter had no name" ) ;
496
+
497
+ // Currently hardcoded to f32/f64 exchange; can be generalized if needed.
498
+ let body_code = quote ! {
499
+ let #param_name = #param_name as f32 ;
500
+ #original_body
501
+ } ;
502
+
503
+ let wrapping_body = Group :: new ( Delimiter :: Brace , body_code) ;
495
504
496
- updated_function = Some ( ( new_params, body ) ) ;
505
+ updated_function = Some ( ( new_params, wrapping_body ) ) ;
497
506
}
498
507
499
508
// Overridden ready() methods additionally have an additional `__before_ready()` call (for OnReady inits).
0 commit comments