JDK-8062799 : Binary logical expressions can have numeric types
  • Type: Bug
  • Component: core-libs
  • Sub-Component: jdk.nashorn
  • Affected Version: 8u40
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2014-11-04
  • Updated: 2015-06-04
  • Resolved: 2014-11-11
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
8u40Fixed 9 b40Fixed
Currently expressions using the || and && operators are always set to Object type. However, these operators evaluate to their left or right hand side without conversion to Boolean, so they should use the widest numeric type of lhs and rhs if possible.

Yes, your fix looks correct. I'm adding tests.

I have a patch for this in the drawer, it's pretty trivial really. It just needs a test, and I wasn't 100% sure Type.widestReturnType is the correct method to use here.