diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2024-06-28 11:35:27 +0200 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2024-06-28 11:35:27 +0200 |
commit | 90bd2c2d0d4fdeeb8dd2b1cd4f84b3c5dc061951 (patch) | |
tree | 2c670042dd6a7d2f819f8a51e7376b11ccc3be1e /modules/gdscript/gdscript_analyzer.cpp | |
parent | 7035aa1a48b8936c8ed66821ad4bcd021732baed (diff) | |
parent | 68898dbcc9444dcbb45a5261aa8f9d4a2dd7390d (diff) | |
download | redot-engine-90bd2c2d0d4fdeeb8dd2b1cd4f84b3c5dc061951.tar.gz |
Merge pull request #93691 from dalexeev/gds-confusable-capture-reassignment
GDScript: Add `CONFUSABLE_CAPTURE_REASSIGNMENT` warning
Diffstat (limited to 'modules/gdscript/gdscript_analyzer.cpp')
-rw-r--r-- | modules/gdscript/gdscript_analyzer.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/modules/gdscript/gdscript_analyzer.cpp b/modules/gdscript/gdscript_analyzer.cpp index 76e690a083..9147204a9b 100644 --- a/modules/gdscript/gdscript_analyzer.cpp +++ b/modules/gdscript/gdscript_analyzer.cpp @@ -2663,6 +2663,21 @@ void GDScriptAnalyzer::reduce_assignment(GDScriptParser::AssignmentNode *p_assig reduce_expression(p_assignment->assignee); +#ifdef DEBUG_ENABLED + { + GDScriptParser::ExpressionNode *base = p_assignment->assignee; + while (base && base->type == GDScriptParser::Node::SUBSCRIPT) { + 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); + } + } + } +#endif + if (p_assignment->assigned_value == nullptr || p_assignment->assignee == nullptr) { return; } |