Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement support for JLS 15.22.2 #32

Closed
GoogleCodeExporter opened this issue Apr 22, 2015 · 3 comments
Closed

Implement support for JLS 15.22.2 #32

GoogleCodeExporter opened this issue Apr 22, 2015 · 3 comments

Comments

@GoogleCodeExporter
Copy link

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

Attachments:

@GoogleCodeExporter
Copy link
Author

This issue was closed by revision r36.

Original comment by matthew....@gatech.edu on 25 Apr 2010 at 2:46

  • Changed state: Fixed

@GoogleCodeExporter
Copy link
Author

milestone=2.1b0

Original comment by pejob...@gmail.com on 25 Feb 2011 at 5:55

  • Added labels: milestone-2.1b0

@GoogleCodeExporter
Copy link
Author

Original comment by pejob...@gmail.com on 20 Oct 2011 at 7:12

  • Added labels: v2.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant