vineflower icon indicating copy to clipboard operation
vineflower copied to clipboard

"Variable is already defined in the scope" error

Open zsrv opened this issue 1 year ago • 1 comments

Version: Quiltflower 1.10.0 (commit 1736a2c41f7a5cade89b1f3aa602b30778644920)

Original code:

import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.stream.StreamResult;
import java.io.StringWriter;

public class Example {
    public static Transformer newTransformer() {
        return null;
    }

    public String myMethod() {
        Source source = null;
        try {
            if (source == null) {
                String string = null;
                return string;
            }
            StringWriter stringWriter = new StringWriter();
            StreamResult streamResult = new StreamResult(stringWriter);
            newTransformer().transform(source, streamResult);
            String string = stringWriter.getBuffer().toString();
            return string;
        }
        catch (Exception e) {
            throw new RuntimeException(e);
        }
        finally {
            if (source != null) {
                System.out.println(".");
            }
        }
    }
}

Quiltflower output:

import java.io.StringWriter;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.stream.StreamResult;

public class Example {
   public static Transformer newTransformer() {
      return null;
   }

   public String myMethod() {
      Source source = null;

      String streamResult;
      try {
         if (source != null) {
            StringWriter stringWriter = new StringWriter();
            StreamResult streamResult = new StreamResult(stringWriter);
            newTransformer().transform(source, streamResult);
            return stringWriter.getBuffer().toString();
         }

         String string = null;
         streamResult = string;
      } catch (Exception var9) {
         throw new RuntimeException(var9);
      } finally {
         if (source != null) {
            System.out.println(".");
         }
      }

      return streamResult;
   }
}

The output results in this error:

Variable 'streamResult' is already defined in the scope

zsrv avatar Apr 12 '23 00:04 zsrv