Skip to content

Commit bb9c28c

Browse files
committed
Add groups export.
- Prevent declaring subgroup without group.
1 parent 462b358 commit bb9c28c

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

godot-macros/src/class/data_models/group_export.rs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77

88
use crate::class::data_models::fields::Fields;
9-
use crate::util::KvParser;
9+
use crate::util::{bail, KvParser};
1010
use crate::ParseResult;
1111
use std::cmp::Ordering;
1212

@@ -45,9 +45,21 @@ impl FieldGroup {
4545
parser: &mut KvParser,
4646
groups: &mut Vec<String>,
4747
) -> ParseResult<Self> {
48+
let (group_name_index, subgroup_name_index) = (
49+
Self::parse_group("group", parser, groups)?,
50+
Self::parse_group("subgroup", parser, groups)?,
51+
);
52+
53+
// Declaring only a subgroup for given property – with no group at all – is totally valid in Godot.
54+
// Unfortunately it leads to a lot of very janky and not too ideal behaviours
55+
// So it is better to treat it as a user error.
56+
if subgroup_name_index.is_some() && group_name_index.is_none() {
57+
return bail!(parser.span(), "Subgroups without groups are not supported.");
58+
}
59+
4860
Ok(Self {
49-
group_name_index: Self::parse_group("group", parser, groups)?,
50-
subgroup_name_index: Self::parse_group("subgroup", parser, groups)?,
61+
group_name_index,
62+
subgroup_name_index,
5163
})
5264
}
5365
}

itest/rust/src/object_tests/property_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ struct CheckAllExports {
242242
#[export(group = "test_group")]
243243
grouped: i64,
244244

245-
#[export(subgroup = "test_subgroup")]
245+
#[export(group = "another group")]
246246
subgrouped: i64,
247247

248248
#[export(group = "test_group", subgroup = "test_subgroup")]

0 commit comments

Comments
 (0)