diff --git a/core/src/main/java/org/teavm/backend/wasm/generate/gc/classes/WasmGCClassGenerator.java b/core/src/main/java/org/teavm/backend/wasm/generate/gc/classes/WasmGCClassGenerator.java index 5cf5d6cb7..761095795 100644 --- a/core/src/main/java/org/teavm/backend/wasm/generate/gc/classes/WasmGCClassGenerator.java +++ b/core/src/main/java/org/teavm/backend/wasm/generate/gc/classes/WasmGCClassGenerator.java @@ -407,6 +407,7 @@ public class WasmGCClassGenerator implements WasmGCClassInfoProvider, WasmGCInit || expectedFunctionType != function.getType()) { var functionType = typeMapper.getFunctionType(virtualTable.getClassName(), method, true); functionType.getSupertypes().add(expectedFunctionType); + expectedFunctionType.setFinal(false); var wrapperFunction = new WasmFunction(functionType); module.functions.add(wrapperFunction); var call = new WasmCall(function); diff --git a/core/src/main/java/org/teavm/backend/wasm/model/WasmFunctionType.java b/core/src/main/java/org/teavm/backend/wasm/model/WasmFunctionType.java index 911fe89c1..7271ea63b 100644 --- a/core/src/main/java/org/teavm/backend/wasm/model/WasmFunctionType.java +++ b/core/src/main/java/org/teavm/backend/wasm/model/WasmFunctionType.java @@ -26,6 +26,7 @@ public class WasmFunctionType extends WasmCompositeType { private Supplier> parameterTypesSupplier; private Supplier returnTypeSupplier; private Set supertypes = new LinkedHashSet<>(); + private boolean isFinal = true; public WasmFunctionType(String name, WasmType returnType, List parameterTypes) { super(name); @@ -60,6 +61,14 @@ public class WasmFunctionType extends WasmCompositeType { return supertypes; } + public boolean isFinal() { + return isFinal; + } + + public void setFinal(boolean aFinal) { + isFinal = aFinal; + } + @Override public void acceptVisitor(WasmCompositeTypeVisitor visitor) { visitor.visit(this); diff --git a/core/src/main/java/org/teavm/backend/wasm/render/WasmCompositeTypeBinaryRenderer.java b/core/src/main/java/org/teavm/backend/wasm/render/WasmCompositeTypeBinaryRenderer.java index a3132396b..630c29337 100644 --- a/core/src/main/java/org/teavm/backend/wasm/render/WasmCompositeTypeBinaryRenderer.java +++ b/core/src/main/java/org/teavm/backend/wasm/render/WasmCompositeTypeBinaryRenderer.java @@ -57,10 +57,12 @@ public class WasmCompositeTypeBinaryRenderer implements WasmCompositeTypeVisitor @Override public void visit(WasmFunctionType type) { - section.writeByte(0x50); - section.writeLEB(type.getSupertypes().size()); - for (var supertype : type.getSupertypes()) { - section.writeLEB(module.types.indexOf(supertype)); + if (!type.isFinal() || !type.getSupertypes().isEmpty()) { + section.writeByte(0x50); + section.writeLEB(type.getSupertypes().size()); + for (var supertype : type.getSupertypes()) { + section.writeLEB(module.types.indexOf(supertype)); + } } section.writeByte(0x60); section.writeLEB(type.getParameterTypes().size());