Skip to content

Commit 0557d4c

Browse files
authored
Merge pull request #747 from Dheatly23/fix-incorrect-itrait-impl
Constraint `ITrait` Bound to it's Corresponding Class
2 parents 0bb3ada + a23f00f commit 0557d4c

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

godot-codegen/src/generator/virtual_traits.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub fn make_virtual_methods_trait(
2323
view: &ApiView,
2424
) -> TokenStream {
2525
let trait_name = ident(trait_name_str);
26+
let class_name = &class.name().rust_ty;
2627

2728
let virtual_method_fns = make_all_virtual_methods(class, all_base_names, view);
2829
let special_virtual_methods = make_special_virtual_methods(notification_enum_name);
@@ -34,7 +35,7 @@ pub fn make_virtual_methods_trait(
3435
#[allow(unused_variables)]
3536
#[allow(clippy::unimplemented)]
3637
#cfg_attributes
37-
pub trait #trait_name: crate::obj::GodotClass + crate::private::You_forgot_the_attribute__godot_api {
38+
pub trait #trait_name: crate::obj::GodotClass<Base = #class_name> + crate::private::You_forgot_the_attribute__godot_api {
3839
#special_virtual_methods
3940
#( #virtual_method_fns )*
4041
}

godot-macros/src/lib.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,21 @@ pub fn derive_godot_class(input: TokenStream) -> TokenStream {
547547
/// }
548548
/// ```
549549
///
550+
/// Using _any_ trait other than the one corresponding with the base class will result in compilation failure.
551+
///
552+
/// ```compile_fail
553+
/// # use godot::prelude::*;
554+
/// #[derive(GodotClass)]
555+
/// #[class(init, base=Node3D)]
556+
/// pub struct My3DNode;
557+
///
558+
/// #[godot_api]
559+
/// impl INode for My3DNode {
560+
/// fn ready(&mut self) {
561+
/// godot_print!("Hello World!");
562+
/// }
563+
/// }
564+
/// ```
550565
///
551566
/// # User-defined functions
552567
///

0 commit comments

Comments
 (0)