mirror of
https://github.com/godotengine/godot.git
synced 2024-11-27 09:16:35 +08:00
Merge pull request #21279 from vnen/gdscript-fixes
Assorted GDScript fixes
This commit is contained in:
commit
a6979e7c66
@ -606,9 +606,11 @@ Error GDScript::reload(bool p_keep_state) {
|
||||
}
|
||||
#if DEBUG_ENABLED
|
||||
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) + ": ";
|
||||
msg += E->get().get_message();
|
||||
WARN_PRINTS(msg);
|
||||
const GDScriptWarning &warning = E->get();
|
||||
if (ScriptDebugger::get_singleton()) {
|
||||
Vector<ScriptLanguage::StackInfo> si;
|
||||
ScriptDebugger::get_singleton()->send_error("", get_path(), warning.line, warning.get_name(), warning.get_message(), ERR_HANDLER_WARNING, si);
|
||||
}
|
||||
}
|
||||
#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;
|
||||
}
|
||||
|
||||
if (!p_class->owner) {
|
||||
if (p_class->owner) {
|
||||
parsed_classes.insert(p_class->name);
|
||||
if (parsing_classes.has(p_class->name)) {
|
||||
parsing_classes.erase(p_class->name);
|
||||
}
|
||||
}
|
||||
|
||||
//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);
|
||||
if (err)
|
||||
return err;
|
||||
parsing_classes.erase(name);
|
||||
}
|
||||
|
||||
#ifdef TOOLS_ENABLED
|
||||
|
@ -2024,12 +2024,20 @@ GDScriptParser::PatternNode *GDScriptParser::_parse_pattern(bool p_static) {
|
||||
// bind
|
||||
case GDScriptTokenizer::TK_PR_VAR: {
|
||||
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->bind = tokenizer->get_token_identifier();
|
||||
// Check if binding is already used
|
||||
if (current_block->variables.has(pattern->bind)) {
|
||||
_set_error("Binding name of '" + pattern->bind.operator String() + "' was already used in the pattern.");
|
||||
return NULL;
|
||||
// Check if variable name is already used
|
||||
BlockNode *bl = current_block;
|
||||
while (bl) {
|
||||
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
|
||||
LocalVarNode *lv = alloc_node<LocalVarNode>();
|
||||
@ -7389,7 +7397,7 @@ void GDScriptParser::_check_function_types(FunctionNode *p_function) {
|
||||
}
|
||||
}
|
||||
#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());
|
||||
}
|
||||
#endif // DEBUG_ENABLED
|
||||
@ -7847,10 +7855,12 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) {
|
||||
// Warnings check
|
||||
for (Map<StringName, LocalVarNode *>::Element *E = p_block->variables.front(); E; E = E->next()) {
|
||||
LocalVarNode *lv = E->get();
|
||||
if (lv->usages == 0) {
|
||||
_add_warning(GDScriptWarning::UNUSED_VARIABLE, lv->line, lv->name);
|
||||
} else if (lv->assignments == 0) {
|
||||
_add_warning(GDScriptWarning::UNASSIGNED_VARIABLE, lv->line, lv->name);
|
||||
if (!lv->name.operator String().begins_with("_")) {
|
||||
if (lv->usages == 0) {
|
||||
_add_warning(GDScriptWarning::UNUSED_VARIABLE, lv->line, lv->name);
|
||||
} else if (lv->assignments == 0) {
|
||||
_add_warning(GDScriptWarning::UNASSIGNED_VARIABLE, lv->line, lv->name);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif // DEBUG_ENABLED
|
||||
|
@ -283,8 +283,14 @@ public:
|
||||
virtual String get_token_error(int p_offset = 0) const;
|
||||
virtual void advance(int p_amount = 1);
|
||||
#ifdef DEBUG_ENABLED
|
||||
virtual const Vector<Pair<int, String> > &get_warning_skips() const { return Vector<Pair<int, String> >(); }
|
||||
virtual const Set<String> &get_warning_global_skips() const { return Set<String>(); }
|
||||
virtual const Vector<Pair<int, String> > &get_warning_skips() const {
|
||||
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; }
|
||||
#endif // DEBUG_ENABLED
|
||||
GDScriptTokenizerBuffer();
|
||||
|
Loading…
Reference in New Issue
Block a user