Skip to content

Commit c3c09f3

Browse files
authored
Merge pull request #1385 from godot-rust/bugfix/array-codegen
Fix codegen regression: `Array<Option<Gd>>` -> `Array<Gd>`
2 parents 3a75a3b + 84c0c11 commit c3c09f3

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

godot-codegen/src/conv/type_conversions.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,11 @@ fn to_rust_type_uncached(full_ty: &GodotTy, ctx: &mut Context) -> RustTy {
232232
elem_type: quote! { Array<#rust_elem_ty> },
233233
}
234234
} else {
235+
// In Array, store Gd and not Option<Gd> elements.
236+
let without_option = rust_elem_ty.tokens_non_null();
237+
235238
RustTy::EngineArray {
236-
tokens: quote! { Array<#rust_elem_ty> },
239+
tokens: quote! { Array<#without_option> },
237240
elem_class: elem_ty.to_string(),
238241
}
239242
};

itest/rust/src/object_tests/object_test.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,11 @@
1111
use std::cell::{Cell, RefCell};
1212
use std::rc::Rc;
1313

14-
use godot::builtin::{GString, StringName, Variant, Vector3};
14+
use godot::builtin::{Array, GString, StringName, Variant, Vector3};
1515
use godot::classes::{
1616
file_access, Engine, FileAccess, IRefCounted, Node, Node2D, Node3D, Object, RefCounted,
1717
};
1818
use godot::global::godot_str;
19-
#[allow(deprecated)]
2019
use godot::meta::{FromGodot, GodotType, ToGodot};
2120
use godot::obj::{Base, Gd, Inherits, InstanceId, NewAlloc, NewGd, RawGd, Singleton};
2221
use godot::register::{godot_api, GodotClass};
@@ -878,6 +877,10 @@ fn object_get_scene_tree(ctx: &TestContext) {
878877

879878
let count = tree.get_child_count();
880879
assert_eq!(count, 1);
880+
881+
// Explicit type as regression test: https://github.com/godot-rust/gdext/pull/1385
882+
let nodes: Array<Gd<Node>> = tree.get_children();
883+
assert_eq!(nodes.len(), 1);
881884
} // implicitly tested: node does not leak
882885

883886
#[itest]

0 commit comments

Comments
 (0)