Skip to content

Commit b1e3621

Browse files
authored
Merge pull request #1294 from Yarwin/bugfix/emit-compile-error-for-rpc-attribute-in-secondary-impl-block
Emit proper compile error when `#[rpc]` attribute is used in `#[godot_api(secondary)]` block
2 parents d214181 + 4618bde commit b1e3621

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,13 @@ fn process_godot_fns(
266266

267267
match attr.ty {
268268
ItemAttrType::Func(func, rpc_info) => {
269+
if rpc_info.is_some() && is_secondary_impl {
270+
return bail!(
271+
&function,
272+
"#[rpc] is currently not supported in secondary impl blocks",
273+
)?;
274+
}
275+
269276
let external_attributes = function.attributes.clone();
270277

271278
// Transforms the following.

godot-macros/src/lib.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,38 @@ pub fn derive_godot_class(input: TokenStream) -> TokenStream {
932932
/// pub fn two(&self) { }
933933
/// }
934934
/// ```
935+
///
936+
/// `#[signal]` and `#[rpc]` attributes are not currently supported in secondary `impl` blocks.
937+
///
938+
///```compile_fail
939+
/// # use godot::prelude::*;
940+
/// # #[derive(GodotClass)]
941+
/// # #[class(init, base=Node)]
942+
/// # pub struct MyNode { base: Base<Node> }
943+
/// # // Without primary `impl` block the compilation will always fail (no matter if #[signal] attribute is present or not)
944+
/// # #[godot_api]
945+
/// # impl MyNode {}
946+
/// #[godot_api(secondary)]
947+
/// impl MyNode {
948+
/// #[signal]
949+
/// fn my_signal();
950+
/// }
951+
/// ```
952+
///
953+
///```compile_fail
954+
/// # use godot::prelude::*;
955+
/// # #[derive(GodotClass)]
956+
/// # #[class(init, base=Node)]
957+
/// # pub struct MyNode { base: Base<Node> }
958+
/// # // Without primary `impl` block the compilation will always fail (no matter if #[rpc] attribute is present or not).
959+
/// # #[godot_api]
960+
/// # impl MyNode {}
961+
/// #[godot_api(secondary)]
962+
/// impl MyNode {
963+
/// #[rpc]
964+
/// fn foo(&mut self) {}
965+
/// }
966+
/// ```
935967
#[doc(
936968
alias = "func",
937969
alias = "rpc",

0 commit comments

Comments
 (0)