From b442c9334fb6bc644501ea84d5a8fa804d904d48 Mon Sep 17 00:00:00 2001 From: cpw <13495049+CPWstatic@users.noreply.github.com> Date: Wed, 8 Jun 2022 17:37:24 +0800 Subject: [PATCH] More readable error msg for operator and/or. (#4304) * More readable error msg for operator and/or. * Add test. Co-authored-by: Sophie <84560950+Sophie-Xie@users.noreply.github.com> --- src/graph/visitor/DeduceTypeVisitor.cpp | 15 +++++++++++++-- tests/tck/features/yield/yield.feature | 7 +++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/graph/visitor/DeduceTypeVisitor.cpp b/src/graph/visitor/DeduceTypeVisitor.cpp index 73f947d266a..16fccff4e78 100644 --- a/src/graph/visitor/DeduceTypeVisitor.cpp +++ b/src/graph/visitor/DeduceTypeVisitor.cpp @@ -105,8 +105,19 @@ static const std::unordered_map 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; \ } \ diff --git a/tests/tck/features/yield/yield.feature b/tests/tck/features/yield/yield.feature index 9eb6d8c962b..71afde05e15 100644 --- a/tests/tck/features/yield/yield.feature +++ b/tests/tck/features/yield/yield.feature @@ -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'.