From 9347a6ad6a56964b5e58f4bf342a16c58509b1bc Mon Sep 17 00:00:00 2001 From: James Buck Date: Sun, 17 Nov 2019 17:19:06 -0600 Subject: [PATCH] Trigger an error when trying to define a preexisting signal in GDScript A class can't have multiple signals with the same name, but previously users would not be alerted to a conflict while editing the script where it occurred. Now a helpful error will appear in the editor during script parsing. (cherry picked from commit 9e447393245c3e4e860e964bd6233d263fbe5c58) --- modules/gdscript/gdscript_parser.cpp | 49 ++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp index 7f5e739b6af..3efb8fe9aa3 100644 --- a/modules/gdscript/gdscript_parser.cpp +++ b/modules/gdscript/gdscript_parser.cpp @@ -4094,6 +4094,14 @@ void GDScriptParser::_parse_class(ClassNode *p_class) { sig.name = tokenizer->get_token_identifier(); sig.emissions = 0; sig.line = tokenizer->get_token_line(); + + for (int i = 0; i < current_class->_signals.size(); i++) { + if (current_class->_signals[i].name == sig.name) { + _set_error("The signal \"" + sig.name + "\" already exists in this class (at line: " + itos(current_class->_signals[i].line) + ")."); + return; + } + } + tokenizer->advance(); if (tokenizer->get_token() == GDScriptTokenizer::TK_PARENTHESIS_OPEN) { @@ -7958,6 +7966,47 @@ void GDScriptParser::_check_class_level_types(ClassNode *p_class) { } } + // Signals + DataType base = p_class->base_type; + + while (base.kind == DataType::CLASS) { + ClassNode *base_class = base.class_type; + for (int i = 0; i < p_class->_signals.size(); i++) { + for (int j = 0; j < base_class->_signals.size(); j++) { + if (p_class->_signals[i].name == base_class->_signals[j].name) { + _set_error("The signal \"" + p_class->_signals[i].name + "\" already exists in a parent class.", p_class->_signals[i].line); + return; + } + } + } + base = base_class->base_type; + } + + StringName native; + if (base.kind == DataType::GDSCRIPT || base.kind == DataType::SCRIPT) { + Ref