Skip to content

Fix usage of segmented path attribute with #[func] #439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions godot-macros/src/class/godot_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,10 @@ where
{
let mut found = None;
for (index, attr) in attributes.iter().enumerate() {
let attr_name = attr
.get_single_path_segment()
.expect("get_single_path_segment");
let Some(attr_name) = attr.get_single_path_segment() else {
// Attribute of the form #[segmented::path] can't be what we are looking for
continue;
};

let new_found = match attr_name {
name if name == "func" => {
Expand Down
4 changes: 4 additions & 0 deletions itest/rust/src/register_tests/constant_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ impl HasConstants {

#[constant]
const D: usize = 20 + 33 * 45;

#[constant]
#[rustfmt::skip]
const DONT_PANIC_WITH_SEGMENTED_PATH_ATTRIBUTE: bool = true;
}

#[itest]
Expand Down
10 changes: 10 additions & 0 deletions itest/rust/src/register_tests/func_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ impl GdSelfReference {
self.internal_value = new_value;
}

#[func]
#[rustfmt::skip]
fn func_shouldnt_panic_with_segmented_path_attribute() -> bool {
true
}

#[signal]
#[rustfmt::skip]
fn signal_shouldnt_panic_with_segmented_path_attribute();

#[func]
fn fail_to_update_internal_value_due_to_conflicting_borrow(
&mut self,
Expand Down