Skip to content

Commit

Permalink
More readable error msg for operator and/or. (#4304)
Browse files Browse the repository at this point in the history
* More readable error msg for operator and/or.

* Add test.

Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com>
  • Loading branch information
CPWstatic and Sophie-Xie authored Jun 8, 2022
1 parent 51e15c3 commit b442c93
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/graph/visitor/DeduceTypeVisitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,19 @@ static const std::unordered_map<Value::Type, Value> kConstantValues = {
auto detectValue = prevOp->second OP currentOp->second; \
if (detectValue.isBadNull()) { \
std::stringstream ss; \
ss << "`" << expr->toString() << "' is not a valid expression, " \
<< "can not apply `" << #OP << "' to `" << prev << "' and `" << current << "'."; \
if (strcmp(#OP, "&&") == 0 || strcmp(#OP, "AND") == 0) { \
ss << "`" << expr->toString() << "' is not a valid expression, " \
<< "can not apply `&&' or `AND' operator to `" << prev << "' and `" << current \
<< "'."; \
} else if (strcmp(#OP, "||") == 0 || strcmp(#OP, "OR") == 0) { \
ss << "`" << expr->toString() << "' is not a valid expression, " \
<< "can not apply `||' or `OR' operator to `" << prev << "' and `" << current \
<< "'."; \
} else { \
ss << "`" << expr->toString() << "' is not a valid expression, " \
<< "can not apply `" << #OP << "' operator to `" << prev << "' and `" << current \
<< "'."; \
} \
status_ = Status::SemanticError(ss.str()); \
return; \
} \
Expand Down
7 changes: 7 additions & 0 deletions tests/tck/features/yield/yield.feature
Original file line number Diff line number Diff line change
Expand Up @@ -554,3 +554,10 @@ Feature: Yield Sentence
Then the result should be, in any order, with relax comparison:
| counT(*) | aVg(3) | bit_Or(1) |
| 1 | 3.0 | 1 |

Scenario: Error message for and/or
When executing query:
"""
YIELD -1 AND TRUE;
"""
Then a SemanticError should be raised at runtime: `(-(1) AND true)' is not a valid expression, can not apply `&&' or `AND' operator to `INT' and `BOOL'.

0 comments on commit b442c93

Please sign in to comment.