vineflower icon indicating copy to clipboard operation
vineflower copied to clipboard

Variable might not have been initialized

Open zsrv opened this issue 1 year ago • 0 comments

Version: Quiltflower 1.10.0 (commit d43976c4523bf67344ee61366e997ac43f1927ef)

Original code:

public class Example {
    private void myMethod() {
        Object[] myObjects = new Object[]{};
        int[] myInts = new int[]{1, 2, 3};
        if (myObjects != null) {
            int i;
            int myObjectsLength = myObjects.length;
            for (i = 0; i < myInts.length; ++i) {
                int myInt = myInts[i];
                int[] myInts2 = myInts;
                int myInts2Length = myInts2.length;
                if (myInts2Length != myObjectsLength) {
                    System.out.println(myInts2Length + " " + myObjectsLength);
                }
            }
        }
    }
}

Quiltflower output:

public class Example {
   private void myMethod() {
      Object[] myObjects = new Object[0];
      int[] myInts = new int[]{1, 2, 3};
      if (myObjects != null) {
         for (int myInt : myObjects) {
            int myInts2Length = myInts.length;
            byte myObjectsLength;
            if (myInts2Length != myObjectsLength) {
               System.out.println(myInts2Length + " " + myObjectsLength);
            }
         }
      }
   }
}

The output results in these errors:

Incompatible types. Found: 'int', required: 'java.lang.Object'
Variable 'myObjectsLength' might not have been initialized

zsrv avatar Apr 25 '23 09:04 zsrv