From 5a017a1f5e3fd9bcadeb2367176d0402ce7d77e3 Mon Sep 17 00:00:00 2001 From: HolonProduction Date: Fri, 5 Jun 2026 10:26:56 +0200 Subject: [PATCH] GDScript: Exclude `globals` internal classes in the analyzer --- modules/gdscript/gdscript_analyzer.cpp | 14 +++++++++----- .../scripts/analyzer/errors/invalid_identifier.gd | 3 +++ .../scripts/analyzer/errors/invalid_identifier.out | 3 +++ 3 files changed, 15 insertions(+), 5 deletions(-) create mode 100644 modules/gdscript/tests/scripts/analyzer/errors/invalid_identifier.gd create mode 100644 modules/gdscript/tests/scripts/analyzer/errors/invalid_identifier.out diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index 97aeba684e..1973bfe97d 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -4632,11 +4632,15 @@ void GDScriptAnalyzer::reduce_identifier(GDScriptParser::IdentifierNode *p_ident } if (GDScriptLanguage::get_singleton()->has_any_global_constant(name)) { - Variant constant = GDScriptLanguage::get_singleton()->get_any_global_constant(name); - p_identifier->set_datatype(type_from_variant(constant, p_identifier)); - p_identifier->is_constant = true; - p_identifier->reduced_value = constant; - return; + // We checked for `ClassDB` classes above. Any `ClassDB` class that reaches this point is not exposed and should not be accessible. + // TODO: Remove this check once `globals` does only contain publicly available things. + if (!ClassDB::class_exists(name)) { + Variant constant = GDScriptLanguage::get_singleton()->get_any_global_constant(name); + p_identifier->set_datatype(type_from_variant(constant, p_identifier)); + p_identifier->is_constant = true; + p_identifier->reduced_value = constant; + return; + } } if (CoreConstants::is_global_enum(name)) { diff --git a/modules/gdscript/tests/scripts/analyzer/errors/invalid_identifier.gd b/modules/gdscript/tests/scripts/analyzer/errors/invalid_identifier.gd new file mode 100644 index 0000000000..1ed7255708 --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/invalid_identifier.gd @@ -0,0 +1,3 @@ +func test(): + print(GDScriptFunctionState) + print(GDScriptNativeClass) diff --git a/modules/gdscript/tests/scripts/analyzer/errors/invalid_identifier.out b/modules/gdscript/tests/scripts/analyzer/errors/invalid_identifier.out new file mode 100644 index 0000000000..a5085b931b --- /dev/null +++ b/modules/gdscript/tests/scripts/analyzer/errors/invalid_identifier.out @@ -0,0 +1,3 @@ +GDTEST_ANALYZER_ERROR +>> ERROR at line 2: Identifier "GDScriptFunctionState" not declared in the current scope. +>> ERROR at line 3: Identifier "GDScriptNativeClass" not declared in the current scope.