From 8c15885f4444dd6a405394eb753528ee7dd31103 Mon Sep 17 00:00:00 2001 From: Alexey Andreev Date: Wed, 14 Aug 2024 13:22:27 +0200 Subject: [PATCH] Fix metaprogramming support, fix calculation of virtual tables for final classes --- .../org/teavm/model/classes/VirtualTableBuilder.java | 3 --- .../impl/MetaprogrammingDependencyListener.java | 10 ++++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/core/src/main/java/org/teavm/model/classes/VirtualTableBuilder.java b/core/src/main/java/org/teavm/model/classes/VirtualTableBuilder.java index 8ab98d3cc..00523a84b 100644 --- a/core/src/main/java/org/teavm/model/classes/VirtualTableBuilder.java +++ b/core/src/main/java/org/teavm/model/classes/VirtualTableBuilder.java @@ -130,9 +130,6 @@ public class VirtualTableBuilder { var methodsAtCallSites = methodsUsedAtCallSites.get(className); if (methodsAtCallSites != null) { for (MethodDescriptor methodDesc : methodsAtCallSites) { - if (cls.hasModifier(ElementModifier.FINAL) && !table.entries.containsKey(methodDesc)) { - continue; - } MethodReader method = cls.getMethod(methodDesc); if (method != null && method.getLevel() == AccessLevel.PRIVATE) { continue; diff --git a/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/MetaprogrammingDependencyListener.java b/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/MetaprogrammingDependencyListener.java index c3fbe0dc6..2cefd0fbb 100644 --- a/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/MetaprogrammingDependencyListener.java +++ b/metaprogramming/impl/src/main/java/org/teavm/metaprogramming/impl/MetaprogrammingDependencyListener.java @@ -94,10 +94,11 @@ public class MetaprogrammingDependencyListener extends AbstractDependencyListene if (model.getUsages().size() == 1) { emitSingleUsage(model, pe, paramVars); } else if (model.getUsages().isEmpty()) { - if (model.getMethod().getReturnType() == ValueType.VOID) { + var returnType = model.getMethod().getReturnType(); + if (returnType == ValueType.VOID) { pe.exit(); } else { - pe.constantNull(Object.class).returnValue(); + pe.defaultValue(returnType).returnValue(); } } else { emitMultipleUsage(model, pe, agent, paramVars); @@ -147,10 +148,11 @@ public class MetaprogrammingDependencyListener extends AbstractDependencyListene } choice.otherwise(() -> { - if (methodDep.getReference().getReturnType() == ValueType.VOID) { + var returnType = methodDep.getReference().getReturnType(); + if (returnType == ValueType.VOID) { pe.exit(); } else { - pe.constantNull(Object.class).returnValue(); + pe.defaultValue(returnType).returnValue(); } }); }