summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Marques <george@gmarqu.es>2020-01-09 08:30:14 -0300
committerGeorge Marques <george@gmarqu.es>2020-01-09 08:30:14 -0300
commit7d4fc79eb359263ea4239dd7cd02ab07f90971a5 (patch)
tree23b0d267f214cfcfd758a05a8538964cda331072
parente7b7dc57fc8ecab198695d9bf6a4d694fb5a72a8 (diff)
Add GDScript warning for standalone expression
This makes the error message clearer as it might be used to call functions with side effects.
-rw-r--r--modules/gdscript/gdscript.cpp4
-rw-r--r--modules/gdscript/gdscript.h1
-rw-r--r--modules/gdscript/gdscript_parser.cpp6
3 files changed, 10 insertions, 1 deletions
diff --git a/modules/gdscript/gdscript.cpp b/modules/gdscript/gdscript.cpp
index 5b0210b16d..8abf2ee7ca 100644
--- a/modules/gdscript/gdscript.cpp
+++ b/modules/gdscript/gdscript.cpp
@@ -2051,6 +2051,9 @@ String GDScriptWarning::get_message() const {
CHECK_SYMBOLS(2);
return "The '" + symbols[0] + "' keyword is deprecated and will be removed in a future release, please replace its uses by '" + symbols[1] + "'.";
} break;
+ case STANDALONE_TERNARY: {
+ return "Standalone ternary conditional operator: the return value is being discarded.";
+ }
case WARNING_MAX: break; // Can't happen, but silences warning
}
ERR_FAIL_V_MSG(String(), "Invalid GDScript warning code: " + get_name_from_code(code) + ".");
@@ -2092,6 +2095,7 @@ String GDScriptWarning::get_name_from_code(Code p_code) {
"UNSAFE_CAST",
"UNSAFE_CALL_ARGUMENT",
"DEPRECATED_KEYWORD",
+ "STANDALONE_TERNARY",
NULL
};
diff --git a/modules/gdscript/gdscript.h b/modules/gdscript/gdscript.h
index cc25c1c313..72389cdddc 100644
--- a/modules/gdscript/gdscript.h
+++ b/modules/gdscript/gdscript.h
@@ -297,6 +297,7 @@ struct GDScriptWarning {
UNSAFE_CAST, // Cast used in an unknown type
UNSAFE_CALL_ARGUMENT, // Function call argument is of a supertype of the require argument
DEPRECATED_KEYWORD, // The keyword is deprecated and should be replaced
+ STANDALONE_TERNARY, // Return value of ternary expression is discarded
WARNING_MAX,
} code;
Vector<String> symbols;
diff --git a/modules/gdscript/gdscript_parser.cpp b/modules/gdscript/gdscript_parser.cpp
index fc35678e65..54e6f43917 100644
--- a/modules/gdscript/gdscript_parser.cpp
+++ b/modules/gdscript/gdscript_parser.cpp
@@ -8274,7 +8274,11 @@ void GDScriptParser::_check_block_types(BlockNode *p_block) {
_mark_line_as_safe(op->line);
_reduce_node_type(op); // Test for safety anyway
#ifdef DEBUG_ENABLED
- _add_warning(GDScriptWarning::STANDALONE_EXPRESSION, statement->line);
+ if (op->op == OperatorNode::OP_TERNARY_IF) {
+ _add_warning(GDScriptWarning::STANDALONE_TERNARY, statement->line);
+ } else {
+ _add_warning(GDScriptWarning::STANDALONE_EXPRESSION, statement->line);
+ }
#endif // DEBUG_ENABLED
}
}