mvel icon indicating copy to clipboard operation
mvel copied to clipboard

MathProcessor narrowing types

Open dohrayme opened this issue 13 years ago • 1 comments

MVEL 2.0.19

If I have a function:

def abs(x) { (x >= 0) ? x : -x }

and use it thus: abs(Integer / BigDecimal)

where the egress type is going to be (is fixed to be) a BigDecimal, a ClassCast exception is thrown during the abs function negation step. Investigating I see a BigDecimal signer is being used but the division operation result has had its type narrowed to be a Double, see MathsProcessor::_doOperations it always passes true to doBigDecimalArithmetic which results in the type being narrowed. Should this not be conditional on the operands and return type?

dohrayme avatar Aug 05 '11 10:08 dohrayme

Can you confirm this is still a problem in MVEL 2.1.Beta6, because there will be no 2.0.20. 2.1 is the next 2.x.x version.

On Aug 5, 2011, at 6:35 AM, dohrayme wrote:

MVEL 2.0.19

If I have a function:

def abs(x) { (x >= 0) ? x : -x }

and use it thus: abs(Integer / BigDecimal)

where the egress type is going to be (is fixed to be) a BigDecimal, a ClassCast exception is thrown during the abs function negation step. Investigating I see a BigDecimal signer is being used but the division operation result has had its type narrowed to be a Double, see MathsProcessor::_doOperations it always passes true to doBigDecimalArithmetic which results in the type being narrowed. Should this not be conditional on the operands and return type?

Reply to this email directly or view it on GitHub: https://github.com/mikebrock/mvel/issues/20

mikebrock avatar Aug 05 '11 17:08 mikebrock