You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Run the following in BSH 2.1b0 and a Java compiler and runtime:
public class Boolean15_22_2
{
public static boolean T()
{
System.out.println("T");
return true;
}
public static boolean F()
{
System.out.println("F");
return false;
}
public static void main(String[] a)
{
System.out.println(T() | F());
System.out.println(F() & T());
System.out.println(T() ^ T());
}
}
---
It should print:
T
F
true
F
T
false
T
T
false
In bsh 2.1b0 (and I assume all previous versions), it instead throws a
bsh.InterpreterError on each statement in main:
// Error: Internal Error: unimplemented binary operator
bsh.InterpreterError: unimplemented binary operator
at bsh.Primitive.booleanBinaryOperation(Primitive.java:279)
at bsh.Primitive.binaryOperationImpl(Primitive.java:244)
at bsh.Primitive.binaryOperation(Primitive.java:224)
at bsh.BSHBinaryExpression.eval(BSHBinaryExpression.java:139)
at bsh.Interpreter.run(Interpreter.java:469)
at bsh.Interpreter.main(Interpreter.java:405)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.jav
a:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at jline.ConsoleRunner.main(ConsoleRunner.java:69)
The problem is that the booleanBinaryOperation in Primitive.java does not
process the BIT_OR, BIT_AND, and XOR tokens (note that the first two names
are misleading, which partly explains the bug). However, section 15.22.2
(http://java.sun.com/docs/books/jls/third_edition/html/expressions.html#15.22.1)
explicitly requires all three for boolean operands. Note that 15.23 and
15.24 explain that the only difference between '&' and '&&', and '|' and
'||', is whether the second operand is always evaluated.
I have attached a patch that fixes the issue. Note that the code does
eagerly evaluate, as required. This part didn't require any modification.
I will write a test if desired.
Original issue reported on code.google.com by superm401@gmail.com on 20 Apr 2010 at 4:23
Original issue reported on code.google.com by
superm401@gmail.com
on 20 Apr 2010 at 4:23Attachments:
The text was updated successfully, but these errors were encountered: