Skip to content

Commit 56db361

Browse files
committed
Add regression tests for type inference of array![] with Gd/DynGd
1 parent e7db2c1 commit 56db361

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

itest/rust/src/builtin_tests/containers/array_test.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,18 @@ fn array_resize() {
570570
assert_eq!(a, Array::new());
571571
}
572572

573+
// Tests that arrays of objects can be declared without explicit type annotations. A similar test exists for DynGd in dyn_gd_test.rs.
574+
// This has deliberately been added to guard against regressions in case `AsArg` is extended (T: Inherits<Base> support broke this).
575+
fn __array_type_inference() {
576+
let a = Node::new_alloc();
577+
let b = Node::new_alloc();
578+
let _array = array![&a, &b];
579+
580+
let c = ArrayTest::new_gd();
581+
let d = ArrayTest::new_gd();
582+
let _array = array![&c, &d];
583+
}
584+
573585
#[derive(GodotClass, Debug)]
574586
#[class(init, base=RefCounted)]
575587
struct ArrayTest;

itest/rust/src/object_tests/dyn_gd_test.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* License, v. 2.0. If a copy of the MPL was not distributed with this
55
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
66
*/
7+
78
use crate::framework::{expect_panic, itest};
89
// Test that all important dyn-related symbols are in the prelude.
910
use godot::prelude::*;
@@ -352,6 +353,11 @@ fn dyn_gd_store_in_godot_array() {
352353
assert_eq!(array.at(1).dyn_bind().get_hitpoints(), 100);
353354

354355
array.at(1).free();
356+
357+
// Tests also type inference of array![]. Independent variable c.
358+
let c = Gd::from_object(RefcHealth { hp: 33 }).into_dyn();
359+
let array_inferred = array![&c];
360+
assert_eq!(array_inferred.at(0).dyn_bind().get_hitpoints(), 33);
355361
}
356362

357363
#[itest]

0 commit comments

Comments
 (0)