From 7484a7fd95b7547ee649ce77b974ae75694c963d Mon Sep 17 00:00:00 2001 From: Joseph Burton Date: Tue, 30 Sep 2025 13:38:13 +0100 Subject: [PATCH] Call visitAnnotableParameterCount (#1376) --- .../minecraft/AnnotationsApplyVisitor.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/AnnotationsApplyVisitor.java b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/AnnotationsApplyVisitor.java index 96a37748..786b6114 100644 --- a/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/AnnotationsApplyVisitor.java +++ b/src/main/java/net/fabricmc/loom/configuration/providers/minecraft/AnnotationsApplyVisitor.java @@ -28,6 +28,7 @@ import org.objectweb.asm.AnnotationVisitor; import org.objectweb.asm.ClassVisitor; import org.objectweb.asm.FieldVisitor; import org.objectweb.asm.MethodVisitor; +import org.objectweb.asm.Opcodes; import org.objectweb.asm.RecordComponentVisitor; import org.objectweb.asm.Type; import org.objectweb.asm.TypePath; @@ -240,8 +241,19 @@ public record AnnotationsApplyVisitor(AnnotationsData annotationsData) implement } return new MethodVisitor(Constants.ASM_VERSION, mv) { + int syntheticParameterCount = 0; + boolean visitedAnnotableParameterCount = false; boolean hasAddedAnnotations = false; + @Override + public void visitParameter(String name, int access) { + if ((access & Opcodes.ACC_SYNTHETIC) != 0) { + syntheticParameterCount++; + } + + super.visitParameter(name, access); + } + @Override public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) { if (methodData.annotationsToRemove().contains(Type.getType(descriptor).getInternalName())) { @@ -271,6 +283,16 @@ public record AnnotationsApplyVisitor(AnnotationsData annotationsData) implement return super.visitParameterAnnotation(parameter, descriptor, visible); } + @Override + public void visitAnnotableParameterCount(int parameterCount, boolean visible) { + if (!visible && !methodData.parameters().isEmpty()) { + parameterCount = Math.max(parameterCount, Type.getArgumentCount(descriptor) - syntheticParameterCount); + visitedAnnotableParameterCount = true; + } + + super.visitAnnotableParameterCount(parameterCount, visible); + } + @Override public void visitCode() { addMethodAnnotations(); @@ -306,6 +328,11 @@ public record AnnotationsApplyVisitor(AnnotationsData annotationsData) implement } } + if (!visitedAnnotableParameterCount && !methodData.parameters().isEmpty()) { + mv.visitAnnotableParameterCount(Type.getArgumentCount(descriptor) - syntheticParameterCount, false); + visitedAnnotableParameterCount = true; + } + methodData.parameters().forEach((paramIndex, paramData) -> { for (AnnotationNode annotation : paramData.annotationsToAdd()) { AnnotationVisitor av = mv.visitParameterAnnotation(paramIndex, annotation.desc, false);