Missing 'incompatible types' compile time error for "return x > 0 ? 100 : null;"

XMLWordPrintable

    • Type: Bug
    • Resolution: Not an Issue
    • Priority: P4
    • None
    • Affects Version/s: 5.0
    • Component/s: tools
    • x86
    • windows_xp

      FULL PRODUCT VERSION :


      A DESCRIPTION OF THE PROBLEM :
      The following code does not give a compile time error:

          int m(int x) {
              return x > 0 ? 100 : null;
          }

      whereas this equivalent code (correctly) gives a compile time error;

          int m(int x) {
              if (x > 0)
                  return 100;
              else
                  return null;
          }


      % head *Compile.java
      ==> WillCompile.java <==
      class WillCompile {
          int m(int x) {
              return x > 0 ? 100 : null;
          }
      }

      ==> WontCompile.java <==
      class WontCompile {
          int m(int x) {
              if (x > 0)
                  return 100;
              else
                  return null;
          }
      }

      But... WillCompile shouldn't compile.





      REPRODUCIBILITY :
      This bug can be reproduced always.

            Assignee:
            Peter Ahe
            Reporter:
            Tim Bell
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: