Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assorted GDScript fixes #21279

Merged
merged 5 commits into from
Aug 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions modules/gdscript/gdscript.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 4 additions & 2 deletions modules/gdscript/gdscript_compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
28 changes: 19 additions & 9 deletions modules/gdscript/gdscript_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>();
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions modules/gdscript/gdscript_tokenizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,14 @@ class GDScriptTokenizerBuffer : public GDScriptTokenizer {
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();
Expand Down