mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
Fix metaprogramming bugs
This commit is contained in:
parent
7b33bb643e
commit
b61849ce80
|
@ -419,16 +419,16 @@ public class Renderer implements ExprVisitor, StatementVisitor, RenderingContext
|
||||||
List<MethodNode> nonInitMethods = new ArrayList<>();
|
List<MethodNode> nonInitMethods = new ArrayList<>();
|
||||||
MethodHolder clinit = classSource.get(cls.getName()).getMethod(
|
MethodHolder clinit = classSource.get(cls.getName()).getMethod(
|
||||||
new MethodDescriptor("<clinit>", ValueType.VOID));
|
new MethodDescriptor("<clinit>", ValueType.VOID));
|
||||||
|
boolean needsClinit = clinit != null;
|
||||||
List<MethodNode> clinitMethods = new ArrayList<>();
|
List<MethodNode> clinitMethods = new ArrayList<>();
|
||||||
for (MethodNode method : cls.getMethods()) {
|
for (MethodNode method : cls.getMethods()) {
|
||||||
if (clinit == null || (!method.getModifiers().contains(NodeModifier.STATIC)
|
if (needsClinit && (method.getModifiers().contains(NodeModifier.STATIC)
|
||||||
&& !method.getReference().getName().equals("<init>"))) {
|
|| method.getReference().getName().equals("<init>"))) {
|
||||||
nonInitMethods.add(method);
|
|
||||||
} else {
|
|
||||||
clinitMethods.add(method);
|
clinitMethods.add(method);
|
||||||
|
} else {
|
||||||
|
nonInitMethods.add(method);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
boolean needsClinit = clinit != null;
|
|
||||||
|
|
||||||
if (needsClinit) {
|
if (needsClinit) {
|
||||||
writer.append("function ").appendClass(cls.getName()).append("_$clinit()").ws()
|
writer.append("function ").appendClass(cls.getName()).append("_$clinit()").ws()
|
||||||
|
|
|
@ -198,15 +198,9 @@ public abstract class BasicBlockMapper implements InstructionVisitor {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(MonitorEnterInstruction insn) {
|
public void visit(MonitorEnterInstruction insn) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(MonitorExitInstruction insn) {
|
public void visit(MonitorExitInstruction insn) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -157,6 +157,9 @@ public final class ProgramUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Variable copyVar(VariableReader var) {
|
private Variable copyVar(VariableReader var) {
|
||||||
|
if (var == null) {
|
||||||
|
throw new NullPointerException();
|
||||||
|
}
|
||||||
return programCopy.variableAt(var.getIndex());
|
return programCopy.variableAt(var.getIndex());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
*/
|
*/
|
||||||
package org.teavm.classlib.java.lang;
|
package org.teavm.classlib.java.lang;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.*;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -103,4 +103,31 @@ public class VMTest {
|
||||||
}
|
}
|
||||||
private int foo() { return 2; }
|
private int foo() { return 2; }
|
||||||
private void bar() { throw new RuntimeException(); }
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user