gnodet-bot commented on code in PR #26824:
URL: https://github.com/apache/camel/pull/26824#discussion_r4091176627


##########
core/camel-core-languages/src/main/java/org/apache/camel/language/simple/ast/BinaryExpression.java:
##########
@@ -58,10 +59,36 @@ public String toString() {
     }
 
     public boolean acceptLeftNode(SimpleNode lef) {
+        if (lef instanceof UnaryExpression unary && unary.getOperator() == 
UnaryOperatorType.NOT) {
+            // ! negates a function, not a comparison: !${body} == 'x' would 
read as neither of the two things it
+            // could mean, so it is refused and the negated operator is 
offered instead (CAMEL-24984)
+            throw new SimpleParserException(
+                    "! cannot be compared: it negates a function, so negate 
the operator instead, e.g. "
+                                            + operator.toString().replace("=", 
"!=") + " or write "
+                                            + "${" + "..." + "} " + 
negatedOperator() + " value",

Review Comment:
   ⚠️ **Bug in error message for `==` operator (still present from previous 
review)**
   
   `operator.toString().replace("=", "!=")` replaces every `=` character 
independently, so `"==".replace("=", "!=")` produces `"!=!="` instead of 
`"!="`. The error message for `!${body} == 'x'` would read:
   
   ```
   ! cannot be compared: it negates a function, so negate the operator instead, 
e.g. !=!= or write ${...} != value
   ```
   
   `negatedOperator()` already exists and returns the correct string for all 
operators — use it for both occurrences:
   
   ```suggestion
                       "! cannot be compared: it negates a function, so negate 
the operator instead, e.g. "
                                               + negatedOperator() + " or write 
"
                                               + "${" + "..." + "} " + 
negatedOperator() + " value",
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to