You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
The text was updated successfully, but these errors were encountered:
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.
Tested versions
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 variableplayer
in MyBoss:would become
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:
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:
Minimal reproduction project (MRP)
N/A
The text was updated successfully, but these errors were encountered: