gitgabrio commented on code in PR #5761:
URL:
https://github.com/apache/incubator-kie-drools/pull/5761#discussion_r1512619029
##########
drools-model/drools-model-codegen/src/test/java/org/drools/model/codegen/execmodel/TypeCoercionTest.java:
##########
@@ -612,4 +612,30 @@ public void testFloatOperation() {
assertThat(list.size()).isEqualTo(1);
assertThat(list.get(0)).isEqualTo("Mario");
}
+
+ @Test
Review Comment:
Hi @baldimir
COuld you please add a similar test where one of the two components is a
number ?
##########
drools-model/drools-model-codegen/src/main/java/org/drools/model/codegen/execmodel/generator/expressiontyper/ExpressionTyper.java:
##########
@@ -224,16 +225,19 @@ private Optional<TypedExpression>
toTypedExpressionRec(Expression drlxExpr) {
TypedExpression left = optLeft.get();
TypedExpression right = optRight.get();
- ArithmeticCoercedExpression.ArithmeticCoercedExpressionResult
coerced;
- try {
- coerced = new ArithmeticCoercedExpression(left, right,
operator).coerce();
- } catch
(ArithmeticCoercedExpression.ArithmeticCoercedExpressionException e) {
- logger.error("Failed to coerce : {}",
e.getInvalidExpressionErrorResult());
- return empty();
- }
+ // Can be a binary expression of non-numeric types, like String +
customType, etc.
+ if (ClassUtils.isNumericClass(left.getRawClass()) ||
ClassUtils.isNumericClass(right.getRawClass())) {
Review Comment:
Thanks @baldimir
But IIUC the `ArithmeticCoercedExpression` requires one part to be a number
and the other a String. With the above if, the code checks only if one of the
elements is a number, but does not verify if the other is a String. If it is
not, the following
`coerced = new ArithmeticCoercedExpression(left, right, operator).coerce();`
would throw an exception (IINW)
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]