diff --git a/core/src/main/java/org/teavm/backend/javascript/JavaScriptTarget.java b/core/src/main/java/org/teavm/backend/javascript/JavaScriptTarget.java index 67f894372..3583a0304 100644 --- a/core/src/main/java/org/teavm/backend/javascript/JavaScriptTarget.java +++ b/core/src/main/java/org/teavm/backend/javascript/JavaScriptTarget.java @@ -326,6 +326,11 @@ public class JavaScriptTarget implements TeaVMTarget, TeaVMJavaScriptHost { Program program = new Program(); method.setProgram(program); + + for (int i = 0; i <= method.parameterCount(); ++i) { + program.createVariable(); + } + BasicBlock block = program.createBasicBlock(); Variable exceptionVar = program.createVariable(); ConstructInstruction newExceptionInsn = new ConstructInstruction(); diff --git a/core/src/main/java/org/teavm/model/optimization/UnusedVariableElimination.java b/core/src/main/java/org/teavm/model/optimization/UnusedVariableElimination.java index 4a23d50b0..d3b54def2 100644 --- a/core/src/main/java/org/teavm/model/optimization/UnusedVariableElimination.java +++ b/core/src/main/java/org/teavm/model/optimization/UnusedVariableElimination.java @@ -29,6 +29,10 @@ public class UnusedVariableElimination implements MethodOptimization { boolean[] escaping = VariableEscapeAnalyzer.findEscapingVariables(program); boolean[] used = new boolean[escaping.length]; + for (int i = 0; i <= method.parameterCount(); ++i) { + used[i] = true; + } + int[] stack = new int[graph.size() * 2]; int top = 0; for (int i = 0; i < used.length; ++i) { diff --git a/core/src/main/java/org/teavm/model/util/TypeInferer.java b/core/src/main/java/org/teavm/model/util/TypeInferer.java index e617bff93..36db9b292 100644 --- a/core/src/main/java/org/teavm/model/util/TypeInferer.java +++ b/core/src/main/java/org/teavm/model/util/TypeInferer.java @@ -28,7 +28,7 @@ public class TypeInferer { GraphBuilder arrayElemBuilder; public void inferTypes(ProgramReader program, MethodReference method) { - int sz = Math.max(method.parameterCount(), program.variableCount()); + int sz = program.variableCount(); types = new VariableType[sz]; types[0] = VariableType.OBJECT;