-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
GDScript: Disallow mismatching native type when attaching to object #70956
Conversation
This used to allow subtypes to be attached to an object but this is not really expected by the GDScript compiler. It assumes that the `extends` statement is exact, which allow for some optimizations and preemptive errors. There's really no reason to allow different types, even if a subtype, since the only cases for this is to allow some hacks that could be avoided with better solutions.
I usually change the type to a base class when creating UI scenes, especially when the node is a container. This allows me to change the container type without needing to modify the script. |
Same here |
@timothyqiu this is also something that can have a better solution. Changing the node type could also change the type in the script automatically. |
I think this should not be done as a lot of people use this functionality (me included) to make one script for a ton of different types to add a functionality to all of them. |
In general this is used a lot to inherit scripts and reuse the functionality across multiple nodes, which is essentially multiple inheritance. Since this isn't really supported and brings lots of troubles, forbidding would be better. The only acceptable case I can see this being useful is to have a helper script that is attached to multiple nodes itself (e.g. a debug helper for Controls that use This should still be avoided and the only reason it won't be dropped is because we don't yet have alternatives in place. |
This won't be done for now since we don't have a good alternative for the use cases. We can change to a warning once those are available to avoid breaking compatibility in future versions. |
Note: This is a compatibility breakage so it might be too late to change. I did intend to send this quite some time ago but unfortunately there has been unforeseen circumstances. Still, I will open this for the discussion since the only uses for this "feature" are hacks and it does get in the way of somethings the GDScript compiler do to analyze and optimize scripts.
If this is accepted, the PR can be improved with error messages in the editor. We can also consider if this will be done for GDScript or for all languages.
This used to allow subtypes to be attached to an object but this is not really expected by the GDScript compiler. It assumes that the
extends
statement is exact, which allow for some optimizations and preemptive errors.There's really no reason to allow different types, even if a subtype, since the only cases for this is to allow some hacks that could be avoided with better solutions.