Merge pull request #21279 from vnen/gdscript-fixes
Assorted GDScript fixes
This commit is contained in:
commit
a6979e7c66
4 changed files with 36 additions and 16 deletions
|
@ -606,9 +606,11 @@ Error GDScript::reload(bool p_keep_state) {
|
||||||
}
|
}
|
||||||
#if DEBUG_ENABLED
|
#if DEBUG_ENABLED
|
||||||
for (const List<GDScriptWarning>::Element *E = parser.get_warnings().front(); E; E = E->next()) {
|
for (const List<GDScriptWarning>::Element *E = parser.get_warnings().front(); E; E = E->next()) {
|
||||||
String msg = "Script warning: " + E->get().get_name() + " (" + path + ") line " + itos(E->get().line) + ": ";
|
const GDScriptWarning &warning = E->get();
|
||||||
msg += E->get().get_message();
|
if (ScriptDebugger::get_singleton()) {
|
||||||
WARN_PRINTS(msg);
|
Vector<ScriptLanguage::StackInfo> si;
|
||||||
|
ScriptDebugger::get_singleton()->send_error("", get_path(), warning.line, warning.get_name(), warning.get_message(), ERR_HANDLER_WARNING, si);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
|
@ -1994,8 +1994,11 @@ Error GDScriptCompiler::_parse_class_level(GDScript *p_script, GDScript *p_owner
|
||||||
p_script->_signals[name] = p_class->_signals[i].arguments;
|
p_script->_signals[name] = p_class->_signals[i].arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!p_class->owner) {
|
if (p_class->owner) {
|
||||||
parsed_classes.insert(p_class->name);
|
parsed_classes.insert(p_class->name);
|
||||||
|
if (parsing_classes.has(p_class->name)) {
|
||||||
|
parsing_classes.erase(p_class->name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//parse sub-classes
|
//parse sub-classes
|
||||||
|
@ -2011,7 +2014,6 @@ Error GDScriptCompiler::_parse_class_level(GDScript *p_script, GDScript *p_owner
|
||||||
Error err = _parse_class_level(subclass.ptr(), p_script, p_class->subclasses[i], p_keep_state);
|
Error err = _parse_class_level(subclass.ptr(), p_script, p_class->subclasses[i], p_keep_state);
|
||||||
if (err)
|
if (err)
|
||||||
return err;
|
return err;
|
||||||
parsing_classes.erase(name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef TOOLS_ENABLED
|
#ifdef TOOLS_ENABLED
|
||||||
|
|
|
@ -2024,12 +2024,20 @@ GDScriptParser::PatternNode *GDScriptParser::_parse_pattern(bool p_static) {
|
||||||
// bind
|
// bind
|
||||||
case GDScriptTokenizer::TK_PR_VAR: {
|
case GDScriptTokenizer::TK_PR_VAR: {
|
||||||
tokenizer->advance();
|
tokenizer->advance();
|
||||||
|
if (!tokenizer->is_token_literal()) {
|
||||||
|
_set_error("Expected identifier for binding variable name.");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
pattern->pt_type = GDScriptParser::PatternNode::PT_BIND;
|
pattern->pt_type = GDScriptParser::PatternNode::PT_BIND;
|
||||||
pattern->bind = tokenizer->get_token_identifier();
|
pattern->bind = tokenizer->get_token_identifier();
|
||||||
// Check if binding is already used
|
// Check if variable name is already used
|
||||||
if (current_block->variables.has(pattern->bind)) {
|
BlockNode *bl = current_block;
|
||||||
_set_error("Binding name of '" + pattern->bind.operator String() + "' was already used in the pattern.");
|
while (bl) {
|
||||||
return NULL;
|
if (bl->variables.has(pattern->bind)) {
|
||||||
|
_set_error("Binding name of '" + pattern->bind.operator String() + "' is already declared in this scope.");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
bl = bl->parent_block;
|
||||||
}
|
}
|
||||||
// Create local variable for proper identifier detection later
|
// Create local variable for proper identifier detection later
|
||||||
LocalVarNode *lv = alloc_node<LocalVarNode>();
|
LocalVarNode *lv = alloc_node<LocalVarNode>();
|
||||||
|
@ -7389,7 +7397,7 @@ void GDScriptParser::_check_function_types(FunctionNode *p_function) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef DEBUG_ENABLED
|
#ifdef DEBUG_ENABLED
|
||||||
if (p_function->arguments_usage[i] == 0) {
|
if (p_function->arguments_usage[i] == 0 && !p_function->arguments[i].operator String().begins_with("_")) {
|
||||||
_add_warning(GDScriptWarning::UNUSED_ARGUMENT, p_function->line, p_function->name, p_function->arguments[i].operator String());
|
_add_warning(GDScriptWarning::UNUSED_ARGUMENT, p_function->line, p_function->name, p_function->arguments[i].operator String());
|
||||||
}
|
}
|
||||||
#endif // DEBUG_ENABLED
|
#endif // DEBUG_ENABLED
|
||||||
|
@ -7847,10 +7855,12 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) {
|
||||||
// Warnings check
|
// Warnings check
|
||||||
for (Map<StringName, LocalVarNode *>::Element *E = p_block->variables.front(); E; E = E->next()) {
|
for (Map<StringName, LocalVarNode *>::Element *E = p_block->variables.front(); E; E = E->next()) {
|
||||||
LocalVarNode *lv = E->get();
|
LocalVarNode *lv = E->get();
|
||||||
if (lv->usages == 0) {
|
if (!lv->name.operator String().begins_with("_")) {
|
||||||
_add_warning(GDScriptWarning::UNUSED_VARIABLE, lv->line, lv->name);
|
if (lv->usages == 0) {
|
||||||
} else if (lv->assignments == 0) {
|
_add_warning(GDScriptWarning::UNUSED_VARIABLE, lv->line, lv->name);
|
||||||
_add_warning(GDScriptWarning::UNASSIGNED_VARIABLE, lv->line, lv->name);
|
} else if (lv->assignments == 0) {
|
||||||
|
_add_warning(GDScriptWarning::UNASSIGNED_VARIABLE, lv->line, lv->name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif // DEBUG_ENABLED
|
#endif // DEBUG_ENABLED
|
||||||
|
|
|
@ -283,8 +283,14 @@ public:
|
||||||
virtual String get_token_error(int p_offset = 0) const;
|
virtual String get_token_error(int p_offset = 0) const;
|
||||||
virtual void advance(int p_amount = 1);
|
virtual void advance(int p_amount = 1);
|
||||||
#ifdef DEBUG_ENABLED
|
#ifdef DEBUG_ENABLED
|
||||||
virtual const Vector<Pair<int, String> > &get_warning_skips() const { return Vector<Pair<int, String> >(); }
|
virtual const Vector<Pair<int, String> > &get_warning_skips() const {
|
||||||
virtual const Set<String> &get_warning_global_skips() const { return Set<String>(); }
|
static Vector<Pair<int, String> > v;
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
virtual const Set<String> &get_warning_global_skips() const {
|
||||||
|
static Set<String> s;
|
||||||
|
return s;
|
||||||
|
}
|
||||||
virtual const bool is_ignoring_warnings() const { return true; }
|
virtual const bool is_ignoring_warnings() const { return true; }
|
||||||
#endif // DEBUG_ENABLED
|
#endif // DEBUG_ENABLED
|
||||||
GDScriptTokenizerBuffer();
|
GDScriptTokenizerBuffer();
|
||||||
|
|
Loading…
Reference in a new issue