mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 16:14:10 -08:00
When Value.get() called in metaprogramming lambda and not assigned anywhere, capture instance anyway so that if it's a lazy value, it will be computed
This commit is contained in:
parent
da3802d9c5
commit
816a17dfc0
|
@ -824,6 +824,8 @@ public class CompositeMethodGenerator {
|
||||||
insn.setReceiver(var(receiver));
|
insn.setReceiver(var(receiver));
|
||||||
insn.setAssignee(var(instance));
|
insn.setAssignee(var(instance));
|
||||||
add(insn);
|
add(insn);
|
||||||
|
} else {
|
||||||
|
var(instance);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -36,6 +36,7 @@ import org.teavm.metaprogramming.Value;
|
||||||
import org.teavm.metaprogramming.reflect.ReflectField;
|
import org.teavm.metaprogramming.reflect.ReflectField;
|
||||||
import org.teavm.metaprogramming.reflect.ReflectMethod;
|
import org.teavm.metaprogramming.reflect.ReflectMethod;
|
||||||
import org.teavm.metaprogramming.test.subpackage.MetaprogrammingGenerator;
|
import org.teavm.metaprogramming.test.subpackage.MetaprogrammingGenerator;
|
||||||
|
import org.teavm.model.ValueType;
|
||||||
|
|
||||||
@CompileTime
|
@CompileTime
|
||||||
@RunWith(TeaVMTestRunner.class)
|
@RunWith(TeaVMTestRunner.class)
|
||||||
|
@ -395,6 +396,24 @@ public class MetaprogrammingTest {
|
||||||
emit(() -> type);
|
emit(() -> type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void unassignedLazyEvaluated() {
|
||||||
|
withUnassignedLazy(Object.class);
|
||||||
|
assertEquals(23, counter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Meta
|
||||||
|
private static native void withUnassignedLazy(Class<Object> cls);
|
||||||
|
private static void withUnassignedLazy(ReflectClass<Object> cls) {
|
||||||
|
emit(() -> counter = 42);
|
||||||
|
Value<Object> value = lazy(() -> counter = 23);
|
||||||
|
emit(() -> {
|
||||||
|
value.get();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int counter = 0;
|
||||||
|
|
||||||
static class Context {
|
static class Context {
|
||||||
public int a;
|
public int a;
|
||||||
public int b;
|
public int b;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user