Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions modules/gdscript/gdscript_analyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6158,6 +6158,15 @@ void GDScriptAnalyzer::is_shadowing(GDScriptParser::IdentifierNode *p_identifier
} else if (GDScriptParser::get_builtin_type(name) < Variant::VARIANT_MAX) {
parser->push_warning(p_identifier, GDScriptWarning::SHADOWED_GLOBAL_IDENTIFIER, p_context, name, "built-in type");
return;
} else if (name == "PI" || name == "TAU" || name == "INF" || name == "NAN") {
parser->push_warning(p_identifier, GDScriptWarning::SHADOWED_GLOBAL_IDENTIFIER, p_context, name, "global constant");
return;
} else if (CoreConstants::is_global_constant(name)) {
parser->push_warning(p_identifier, GDScriptWarning::SHADOWED_GLOBAL_IDENTIFIER, p_context, name, "global constant");
return;
Comment thread
EdwardChanCH marked this conversation as resolved.
} else if (CoreConstants::is_global_enum(name)) {
parser->push_warning(p_identifier, GDScriptWarning::SHADOWED_GLOBAL_IDENTIFIER, p_context, name, "global enum");
return;
}
}

Expand Down
2 changes: 1 addition & 1 deletion modules/gdscript/gdscript_warning.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class GDScriptWarning {
UNUSED_SIGNAL, // Signal is defined but never explicitly used in the class.
SHADOWED_VARIABLE, // A local variable/constant shadows a current class member.
SHADOWED_VARIABLE_BASE_CLASS, // A local variable/constant shadows a base class member.
SHADOWED_GLOBAL_IDENTIFIER, // A global class or function has the same name as variable.
SHADOWED_GLOBAL_IDENTIFIER, // A local variable/constant/enum/function shadows a global type, class, function, enum, or constant.
UNREACHABLE_CODE, // Code after a return statement.
UNREACHABLE_PATTERN, // Pattern in a match statement after a catch all pattern (wildcard or bind).
STANDALONE_EXPRESSION, // Expression not assigned to a variable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@ func test():
var base_variable_member
const base_function_member = 1
var base_const_member
var PI = 4
var OK = -1
var Side = -2
var UINT8_MAX = -3

print('warn')
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ GDTEST_OK
~~ WARNING at line 19: (SHADOWED_VARIABLE_BASE_CLASS) The local variable "base_variable_member" is shadowing an already-declared variable at line 4 in the base class "ShadowingBase".
~~ WARNING at line 20: (SHADOWED_VARIABLE_BASE_CLASS) The local constant "base_function_member" is shadowing an already-declared function at line 6 in the base class "ShadowingBase".
~~ WARNING at line 21: (SHADOWED_VARIABLE_BASE_CLASS) The local variable "base_const_member" is shadowing an already-declared constant at line 3 in the base class "ShadowingBase".
~~ WARNING at line 22: (SHADOWED_GLOBAL_IDENTIFIER) The variable "PI" has the same name as a global constant.
~~ WARNING at line 23: (SHADOWED_GLOBAL_IDENTIFIER) The variable "OK" has the same name as a global constant.
~~ WARNING at line 24: (SHADOWED_GLOBAL_IDENTIFIER) The variable "Side" has the same name as a global enum.
~~ WARNING at line 25: (SHADOWED_GLOBAL_IDENTIFIER) The variable "UINT8_MAX" has the same name as a global constant.
warn
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
GDTEST_OK
~~ WARNING at line 6: (SHADOWED_GLOBAL_IDENTIFIER) The variable "PI" has the same name as a global constant.
~~ WARNING at line 9: (SHADOWED_GLOBAL_IDENTIFIER) The variable "INF" has the same name as a global constant.
~~ WARNING at line 12: (SHADOWED_GLOBAL_IDENTIFIER) The variable "NAN" has the same name as a global constant.
~~ WARNING at line 15: (SHADOWED_GLOBAL_IDENTIFIER) The variable "TAU" has the same name as a global constant.
match
PI
INF
Expand Down
Loading