Skip to content

Commit 765d2a7

Browse files
committed
Test required params/returns (currently UB)
1 parent e430cce commit 765d2a7

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

godot-codegen/src/lib.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,15 @@ pub const IS_CODEGEN_FULL: bool = false;
5252
pub const IS_CODEGEN_FULL: bool = true;
5353

5454
#[cfg(all(feature = "experimental-required-objs", before_api = "4.6"))]
55-
compile_error!("The `experimental-required-objs` feature needs at least Godot 4.6-dev version");
55+
fn __feature_warning() {
56+
// Not a hard error, it's experimental anyway and allows more flexibility like this.
57+
#[must_use = "The `experimental-required-objs` feature needs at least Godot 4.6-dev version"]
58+
fn feature_has_no_effect() -> i32 {
59+
1
60+
}
61+
62+
feature_has_no_effect();
63+
}
5664

5765
fn write_file(path: &Path, contents: String) {
5866
let dir = path.parent().unwrap();

itest/rust/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ crate-type = ["cdylib"]
1313
# Default feature MUST be empty for workflow reasons, even if it differs from the default feature set in upstream `godot` crate.
1414
default = []
1515
codegen-full = ["godot/__codegen-full"]
16-
codegen-full-experimental = ["codegen-full", "godot/experimental-godot-api"]
16+
codegen-full-experimental = ["codegen-full", "godot/experimental-godot-api", "godot/experimental-required-objs"]
1717
experimental-threads = ["godot/experimental-threads"]
1818
register-docs = ["godot/register-docs"]
1919
serde = ["dep:serde", "dep:serde_json", "godot/serde"]

itest/rust/src/engine_tests/node_test.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,25 @@ fn node_call_group(ctx: &TestContext) {
7474
tree.call_group("group", "remove_meta", vslice!["something"]);
7575
assert!(!node.has_meta("something"));
7676
}
77+
78+
// Experimental required parameter/return value: https://github.com/godot-rust/gdext/pull/1383.
79+
#[cfg(all(feature = "codegen-full-experimental", since_api = "4.6"))]
80+
#[itest(focus)]
81+
fn node_required_param_return() {
82+
use godot::classes::Tween;
83+
use godot::obj::Gd;
84+
85+
let mut parent = Node::new_alloc();
86+
let child = Node::new_alloc();
87+
88+
// add_child() takes required arg, so this still works.
89+
// (Test for Option *not* working anymore is in godot > no_compile_tests.)
90+
parent.add_child(&child);
91+
92+
// create_tween() returns now non-null instance.
93+
let tween: Gd<Tween> = parent.create_tween();
94+
assert!(tween.is_instance_valid());
95+
assert!(tween.to_string().contains("Tween"));
96+
97+
parent.free();
98+
}

0 commit comments

Comments
 (0)