diff options
| author | Rémi Verschelde <rverschelde@gmail.com> | 2024-06-28 15:55:05 +0200 |
|---|---|---|
| committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-06-28 15:55:05 +0200 |
| commit | 47776856d6831d03c961663c95b030aaa9cbfd0c (patch) | |
| tree | 459b6ddeaa9aaf375b782f88824131d43de9fda4 /modules/gdscript/gdscript_analyzer.cpp | |
| parent | 52d7ff86f76d7aeb7ce5fe1fe1c92770a6dffa9f (diff) | |
| parent | d15ed0bcbb17284289146da53fff7e29bef71223 (diff) | |
| download | redot-engine-47776856d6831d03c961663c95b030aaa9cbfd0c.tar.gz | |
Merge pull request #93699 from dalexeev/gds-fix-false-positive-capture-warnings
GDScript: Fix false positive `CONFUSABLE_CAPTURE_REASSIGNMENT` warnings
Diffstat (limited to 'modules/gdscript/gdscript_analyzer.cpp')
| -rw-r--r-- | modules/gdscript/gdscript_analyzer.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index 9147204a9b..a6b4bce000 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -2665,14 +2665,37 @@ void GDScriptAnalyzer::reduce_assignment(GDScriptParser::AssignmentNode *p_assig #ifdef DEBUG_ENABLED { + bool is_subscript = false; GDScriptParser::ExpressionNode *base = p_assignment->assignee; while (base && base->type == GDScriptParser::Node::SUBSCRIPT) { + is_subscript = true; base = static_cast<GDScriptParser::SubscriptNode *>(base)->base; } if (base && base->type == GDScriptParser::Node::IDENTIFIER) { GDScriptParser::IdentifierNode *id = static_cast<GDScriptParser::IdentifierNode *>(base); if (current_lambda && current_lambda->captures_indices.has(id->name)) { - parser->push_warning(p_assignment, GDScriptWarning::CONFUSABLE_CAPTURE_REASSIGNMENT, id->name); + bool need_warn = false; + if (is_subscript) { + const GDScriptParser::DataType &id_type = id->datatype; + if (id_type.is_hard_type()) { + switch (id_type.kind) { + case GDScriptParser::DataType::BUILTIN: + // TODO: Change `Variant::is_type_shared()` to include packed arrays? + need_warn = !Variant::is_type_shared(id_type.builtin_type) && id_type.builtin_type < Variant::PACKED_BYTE_ARRAY; + break; + case GDScriptParser::DataType::ENUM: + need_warn = true; + break; + default: + break; + } + } + } else { + need_warn = true; + } + if (need_warn) { + parser->push_warning(p_assignment, GDScriptWarning::CONFUSABLE_CAPTURE_REASSIGNMENT, id->name); + } } } } |
