Skip to content

Add static variable shadowing #12505

Open
@gunbuilderguy

Description

@gunbuilderguy

Describe the project you are working on

This feature applies to many projects, i'm afraid my example would only cause misunderstandings

Describe the problem or limitation you are having in your project

As of the latest version and prior (4.4.X+), It's impossible to have variable shadowing.
While it's possible to shadow methods, that is as far as it goes, you aren't able to have a re-assignment of an existing static variable's value as the inheritor of a base class.
Current ways to go around it is to have these kinds of variables be resources, but you end up sacrificing on readability and lack the assurance that a variable exists in any solid manner.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

class foo:
  static var a : int = 50

class bar extends foo:
  static var a : int = 70

Allowing such would avoid much headache around having to skirt around this issue.

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

While I've done some amount of delving in the compiler some time back, I think it shouldn't be too far from mirroring the shadowing implementation for methods that exists currently.

A Ctrl + Click would similarly allow one to navigate to the variable being shadowed, or the anterior shadowing variable

Note: I'm proposing to keep the scope at static variable because this issue overwhelmingly affects them and the solution to it is far simpler if we don't try to add shadowing of instance variables, keeping it to static ones only.

If this enhancement will not be used often, can it be worked around with a few lines of script?

I Doubt it, it's c++ compiler business.

Is there a reason why this should be core and not an add-on in the asset library?

This feature is already part of most modern languages and the lack of it in godot is rather puzzling

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions