Issue Details (XML | Word | Printable)

Key: MVEL-83
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Mike Brock
Reporter: Edson Tirelli
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
MVEL

(10-5)*2 + 5*(8-4) == 140 ?

Created: 09/Apr/08 01:41 PM   Updated: 15/Apr/09 04:02 PM
Component/s: None
Affects Version/s: 1.1, 1.2.26
Fix Version/s: 1.3.0

Time Tracking:
Not Specified


 Description  « Hide
I have a question regarding order of operations in the consequence of a rule when using the mvel dialect. When executed the Drl below provides Right =30.0 and Wrong =140.0. The only difference is the parens around the multiplying expressions, which shouldn't be necessary given order of operations. Is this a problem with the drools/mvel interaction or is it completely an issue with mvel?

Is the general expectation that all expressions must be completely scoped by parens when using mvel?

package test;

dialect "mvel"

rule "test 11"

when

then

double rightVal=((10-5)2) + (5(8-4));

double wrongVal=(10-5)2 + 5(8-4);

System.out.println("Right ="+rightVal);

System.out.println("Wrong ="+wrongVal);

End

After execution:

Right =30.0

Wrong =140.0

Thank you for all of your help. We are using drools 4.0.4.

Joe

Also, I haven't figured out how it arrives at 140. The following format also produces 140, which seems a little more strange.

double wrongVal=10-5*2 + 5*8-4;



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Edson Tirelli added a comment - 09/Apr/08 03:16 PM
Another bug that I just came across while working on getting my parens to work involved not handling scoped numbers properly. Similar to the previous one, but different in that it ends the expression evaluation prematurely. See the drl and result below:

package test;

dialect "mvel"

rule "test 12"

when

then

double rightVal=(10 + 12);

double wrongVal=(10) + (12);

double wrongValTwo = ((10)+12)

System.out.println("Right "+rightVal);

System.out.println("Wrong "+wrongVal);

System.out.println("WrongTwo "+wrongValTwo);

End

Results in:

Right 22.0

Wrong 10.0

WrongTwo 10.0


Mike Brock added a comment - 16/Apr/08 01:59 AM
fixed in trunk