Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-1266795

wrong type of shift expressions

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 1.0.2
    • Fix Version/s: 1.1
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      1.1
    • CPU:
      sparc
    • OS:
      generic
    • Verification:
      Not verified

      Description



      Name: ###@###.### Date: 09/05/96

      the compiler determines the type of shift expressions
                   in accordance with the rules of binary promotion
                   (Java Language Specification, section 5.6.2). This contradicts
                   the following assertion:

                   Binary numeric promotion (section 5.6.2) is not performed on
                   the operands; rather, unary numeric promotion (section 5.6.1)
                   is performed on each operand separately. The type of the shift
                   expression is the promoted type of the left-hand operand.

                   (Java Language Specification, section 15.18)

      Tests: compilation of the following test:

      public class test
      {
      public static void main(String argv[])
      {
      int i = 1, j;

      j = i << 1l;
      System.out.println(j);
      j = ++i >> 1l;
      System.out.println(j);
      j = ++i >>> 1l;
      System.out.println(j);
      }
      }

      produces such error diagnostics:

      novo40% javac test.java
      test.java:7: Incompatible type for =. Explicit cast needed to convert long to int.
      j = i << 1l;
      ^
      test.java:9: Incompatible type for =. Explicit cast needed to convert long to int.
      j = ++i >> 1l;
      ^
      test.java:11: Incompatible type for =. Explicit cast needed to convert long to int.
      j = ++i >>> 1l;
      ^
      3 errors

      ======================================================================

        Attachments

          Activity

            People

            • Assignee:
              fyellinsunw Frank Yellin (Inactive)
              Reporter:
              wensunw Wen Wen (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: