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

SHADOWED_VARIABLE warning on variable declared on base class gives line in base class file, which is misleading #101992

Closed
hsandt opened this issue Jan 24, 2025 · 2 comments

Comments

@hsandt
Copy link
Contributor

hsandt commented Jan 24, 2025

Tested versions

  • Reproducible in v4.3.stable.official [77dcf97]

System information

Godot v4.3.stable - Ubuntu 22.04.5 LTS 22.04 - X11 - GLES3 (Compatibility) - NVIDIA GeForce GTX 860M (nvidia; 535.183.01) - Intel(R) Core(TM) i7-4710HQ CPU @ 2.50GHz (8 Threads)

Issue description

The SHADOWED_VARIABLE warning occurs when declaring a variable with the same name as another one defined higher in the same context, or in a higher context.

When declaring a child class (class inheritance), this also occurs for member variables defined on the base class. In this case, the warning message will indicate the line in the base class script file, however it won't mention that it is in a different file, which is misleading to the user (who will find a completely unrelated line in the same file).

It should mention the script along with the line (at least if the script differs from the script containing the shadowing variable). You could indicate the class_name, or the script file (.gd), or both. For the script file it would be less ambiguous to provide the full path to script, however since class_name must be unique it's probably OK to just put the base file name as well.

Ex for a member variable player in BaseBoss shadowed by a local variable player in MyBoss:

The local variable "player" is shadowing an already-declared variable at line 13.
SHADOWED_VARIABLE
my_boss.gd:94

would become

The local variable "player" is shadowing an already-declared variable in BaseBoss (base_boss.gd) at line 13.
SHADOWED_VARIABLE
my_boss.gd:94

Bonus: It would probably be nice to open said line when clicking on the warning message, but I'm not sure if Godot supports multiple target lines (because it needs one target line for the line with the shadowing variable already).

If it does support clicking on extra info then we could add that:

base_boss.gd:13

And clicking on this would send to the shadowing var declaration.

Steps to reproduce

Create those two scripts and run the game to force show warning:

# base_boss.gd
class_name BaseBoss
extends Node2D

var player: Node2D
# my_boss.gd
extends BaseBoss

func ready():
    var player = null

Minimal reproduction project (MRP)

N/A

@dalexeev
Copy link
Member

It changes the warning message format. The message now contains either "in the current class" or the base class FQCN (i.e. either the global name or the file path plus the inner class chain, if any). Please test 4.4 beta 1.

@hsandt
Copy link
Contributor Author

hsandt commented Jan 25, 2025

Thanks, as usual I couldn't find a duplicate when I searched initially, and now I find it easily, typing the right keywords...

Closing this as duplicate of #74395

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