summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2018-08-22 09:53:52 +0200
committerGitHub <noreply@github.com>2018-08-22 09:53:52 +0200
commita6979e7c66c366ad521fc3d8cbd81d911650f030 (patch)
treeeb64f65779a82affe9b53853cd6c67306182d457 /modules
parent703de2f6ece307dd0ddbfd8193d1996f141294c3 (diff)
parent94d662ad558c80b0b04c85ad3daadb24ce653cd9 (diff)
Merge pull request #21279 from vnen/gdscript-fixes
Assorted GDScript fixes
Diffstat (limited to 'modules')
-rw-r--r--modules/gdscript/gdscript.cpp8
-rw-r--r--modules/gdscript/gdscript_compiler.cpp6
-rw-r--r--modules/gdscript/gdscript_parser.cpp28
-rw-r--r--modules/gdscript/gdscript_tokenizer.h10
4 files changed, 36 insertions, 16 deletions
diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp
index b987d2897f..5125b58b41 100644
--- a/modules/gdscript/gdscript.cpp
+++ b/modules/gdscript/gdscript.cpp
@@ -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
diff --git a/modules/gdscript/gdscript_compiler.cpp b/modules/gdscript/gdscript_compiler.cpp
index fe393957db..368601127d 100644
--- a/modules/gdscript/gdscript_compiler.cpp
+++ b/modules/gdscript/gdscript_compiler.cpp
@@ -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
diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp
index bec314866d..2c0d541d8f 100644
--- a/modules/gdscript/gdscript_parser.cpp
+++ b/modules/gdscript/gdscript_parser.cpp
@@ -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
diff --git a/modules/gdscript/gdscript_tokenizer.h b/modules/gdscript/gdscript_tokenizer.h
index 28a08bfaf8..11a291cb2e 100644
--- a/modules/gdscript/gdscript_tokenizer.h
+++ b/modules/gdscript/gdscript_tokenizer.h
@@ -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();