Fix metaprogramming bugs

This commit is contained in:
Alexey Andreev 2015-12-10 23:05:17 +03:00
parent 7b33bb643e
commit b61849ce80
4 changed files with 36 additions and 12 deletions

View File

@ -419,16 +419,16 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
List<MethodNode> nonInitMethods = new ArrayList<>();
MethodHolder clinit = classSource.get(cls.getName()).getMethod(
new MethodDescriptor("<clinit>", ValueType.VOID));
boolean needsClinit = clinit != null;
List<MethodNode> clinitMethods = new ArrayList<>();
for (MethodNode method : cls.getMethods()) {
if (clinit == null || (!method.getModifiers().contains(NodeModifier.STATIC)
&& !method.getReference().getName().equals("<init>"))) {
nonInitMethods.add(method);
} else {
if (needsClinit && (method.getModifiers().contains(NodeModifier.STATIC)
|| method.getReference().getName().equals("<init>"))) {
clinitMethods.add(method);
} else {
nonInitMethods.add(method);
}
}
boolean needsClinit = clinit != null;
if (needsClinit) {
writer.append("function ").appendClass(cls.getName()).append("_$clinit()").ws()

View File

@ -198,15 +198,9 @@ public abstract class BasicBlockMapper implements InstructionVisitor {
@Override
public void visit(MonitorEnterInstruction insn) {
}
@Override
public void visit(MonitorExitInstruction insn) {
}
}

View File

@ -157,6 +157,9 @@ public final class ProgramUtils {
}
private Variable copyVar(VariableReader var) {
if (var == null) {
throw new NullPointerException();
}
return programCopy.variableAt(var.getIndex());
}

View File

@ -15,7 +15,7 @@
*/
package org.teavm.classlib.java.lang;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;
import org.junit.Test;
/**
@ -103,4 +103,31 @@ public class VMTest {
}
private int foo() { return 2; }
private void bar() { throw new RuntimeException(); }
// See https://github.com/konsoletyper/teavm/issues/167
@Test
public void passesStaticFieldToSuperClassConstructor() {
SubClass obj = new SubClass();
assertNotNull(obj.getValue());
}
static class SuperClass {
static final Integer ONE = new Integer(1);
private Integer value;
public SuperClass(Integer value) {
this.value = value;
}
public Integer getValue() {
return value;
}
}
static class SubClass extends SuperClass {
SubClass() {
super(ONE);
}
}
}