@@ -482,3 +482,44 @@ func test_renamed_func_get_set():
482
482
assert_eq(obj.f1(), 84 )
483
483
484
484
obj.free()
485
+
486
+ # -----------------------------------------------------------------------------------------------------------------------------------------------
487
+ # Tests below verify the following:
488
+ # Calling a typed Rust function with a Variant that cannot be converted to the Rust type will cause a failed function call on _GDScript_ side,
489
+ # meaning the GDScript function aborts immediately. This happens because a `Variant -> T` conversion occurs dynamically *on GDScript side*,
490
+ # before the Rust function is called.In contrast, panics inside the Rust function (e.g. variant.to::<T>()) just cause the *Rust* function to fail.
491
+ #
492
+ # Store arguments as Variant, as GDScript wouldn't parse script otherwise. Results in varcall being used.
493
+
494
+ func test_marshalling_fail_variant_type():
495
+ # Expects Object, pass GString.
496
+ var obj := ObjectTest.new()
497
+ var arg: Variant = " not an object"
498
+ obj.pass_object(arg)
499
+
500
+ assert_fail(" GDScript function should fail after marshalling error (bad variant type)" )
501
+
502
+ func test_marshalling_fail_non_null():
503
+ # Expects Object, pass null.
504
+ var obj := ObjectTest.new()
505
+ obj.pass_object(null)
506
+
507
+ assert_fail(" GDScript function should fail after marshalling error (required non-null)" )
508
+
509
+ func test_marshalling_fail_integer_overflow():
510
+ # Expects i32. This overflows.
511
+ var obj := ObjectTest.new()
512
+ var arg: Variant = 9223372036854775807
513
+ obj.pass_i32(arg)
514
+
515
+ assert_fail(" GDScript function should fail after marshalling error (int overflow)" )
516
+
517
+ func test_marshalling_continues_on_panic():
518
+ mark_test_pending()
519
+
520
+ # Expects i32. This overflows.
521
+ var obj := ObjectTest.new()
522
+ var result = obj.cause_panic()
523
+
524
+ assert_eq(result, Vector3.ZERO, " Default value returned on failed function call" )
525
+ mark_test_succeeded()
0 commit comments