Skip to content
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: Allow cyclical references between classes #595

Closed
Wavesonics opened this issue Mar 17, 2020 · 2 comments
Closed

GDScript: Allow cyclical references between classes #595

Wavesonics opened this issue Mar 17, 2020 · 2 comments

Comments

@Wavesonics
Copy link

Wavesonics commented Mar 17, 2020

Describe the project you are working on:
Nuclear Reactor control room simulation

Describe the problem or limitation you are having in your project:
I would love to be able to use static typing throughout my project, but currently I run into several issues that prevent me from doing it very widely.
One major issue is that classes can not reference each other, even transitively. This leads to cyclical reference errors very often, and some times, due to the transitive nature of it, in unexpected cases.
The end result is I often have to just remove the static typing.

Describe the feature / enhancement and how it helps to overcome the problem or limitation:
I recognize that this would probably end up being a pretty big task.
GDScript would probably need to implement some sort of multi-pass complication. First scan every script file collecting public symbols (member variables and functions). Then run a second pass where method bodies are actually evaluated, this time with full knowledge of all of the accessible symbols.

Describe how your proposal will work, with code, pseudocode, mockups, and/or diagrams:
In the end it would allow for something even as tightly coupled as this:

##########################
# ClassA.gd
extends Node
class_name ClassA

var classB: ClassB

func a_method(classB: ClassB):
	classB.b_method(self)

##########################
# ClassB.gd
extends Node
class_name ClassB

var classA: ClassA

func b_method(classA: ClassA):
	classA.a_method(self)

The above is an extreme example, and let me stop you right there, yes it's obviously bad code. However if the type system is robust enough to support that worst case scenerio, then it can support anything we might need to do with it.

If this enhancement will not be used often, can it be worked around with a few lines of script?:
I think it would be used quite often!
However, the work around is just to not use static typing sadly.

Is there a reason why this should be core and not an add-on in the asset library?:
It's fundamental to how GDScript parses scripts, it can't be implemented externally.

@Xrayez
Copy link
Contributor

Xrayez commented Mar 17, 2020

See godotengine/godot#21461, there are certainly plans for resolving this in 4.0.

See also #460 since it can act as a tracker for "cyclic references" proposals/requests.

@aaronfranke
Copy link
Member

Closing this as a duplicate of godotengine/godot#21461

This is a well-known problem which is considered a bug, as such we don't need a proposal for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants