diff --git a/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/CompositeMethodGenerator.java b/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/CompositeMethodGenerator.java index c1e91e688..054c7d0c5 100644 --- a/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/CompositeMethodGenerator.java +++ b/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/CompositeMethodGenerator.java @@ -824,6 +824,8 @@ public class CompositeMethodGenerator { insn.setReceiver(var(receiver)); insn.setAssignee(var(instance)); add(insn); + } else { + var(instance); } return; } else { diff --git a/tests/src/test/java/org/teavm/metaprogramming/test/MetaprogrammingTest.java b/tests/src/test/java/org/teavm/metaprogramming/test/MetaprogrammingTest.java index 337b35621..ca80fccd7 100644 --- a/tests/src/test/java/org/teavm/metaprogramming/test/MetaprogrammingTest.java +++ b/tests/src/test/java/org/teavm/metaprogramming/test/MetaprogrammingTest.java @@ -36,6 +36,7 @@ import org.teavm.metaprogramming.Value; import org.teavm.metaprogramming.reflect.ReflectField; import org.teavm.metaprogramming.reflect.ReflectMethod; import org.teavm.metaprogramming.test.subpackage.MetaprogrammingGenerator; +import org.teavm.model.ValueType; @CompileTime @RunWith(TeaVMTestRunner.class) @@ -395,6 +396,24 @@ public class MetaprogrammingTest { emit(() -> type); } + @Test + public void unassignedLazyEvaluated() { + withUnassignedLazy(Object.class); + assertEquals(23, counter); + } + + @Meta + private static native void withUnassignedLazy(Class cls); + private static void withUnassignedLazy(ReflectClass cls) { + emit(() -> counter = 42); + Value value = lazy(() -> counter = 23); + emit(() -> { + value.get(); + }); + } + + private static int counter = 0; + static class Context { public int a; public int b;