diff --git a/src/main/java/net/fabricmc/tinyremapper/extension/mixin/soft/annotation/injection/CommonInjectionAnnotationVisitor.java b/src/main/java/net/fabricmc/tinyremapper/extension/mixin/soft/annotation/injection/CommonInjectionAnnotationVisitor.java index 762c07f4..47a531a3 100644 --- a/src/main/java/net/fabricmc/tinyremapper/extension/mixin/soft/annotation/injection/CommonInjectionAnnotationVisitor.java +++ b/src/main/java/net/fabricmc/tinyremapper/extension/mixin/soft/annotation/injection/CommonInjectionAnnotationVisitor.java @@ -29,6 +29,7 @@ import net.fabricmc.tinyremapper.api.TrClass; import net.fabricmc.tinyremapper.api.TrMember; import net.fabricmc.tinyremapper.api.TrMember.MemberType; +import net.fabricmc.tinyremapper.api.TrMethod; import net.fabricmc.tinyremapper.extension.mixin.common.IMappable; import net.fabricmc.tinyremapper.extension.mixin.common.ResolveUtility; import net.fabricmc.tinyremapper.extension.mixin.common.data.Annotation; @@ -181,7 +182,20 @@ public MemberInfo result() { .map(target -> resolvePartial(target, info.getName(), info.getDesc())) .filter(Optional::isPresent) .map(Optional::get) - .map(m -> Pair.of(data.mapper.mapName(m), data.mapper.mapDesc(m))) + .map(m -> { + String mappedName = data.mapper.mapName(m); + boolean shouldPassDesc = false; + + for (TrMethod other : m.getOwner().getMethods()) { // look for ambiguous targets + if (other == m) continue; + + if (data.mapper.mapName(other).equals(mappedName)) { + shouldPassDesc = true; + } + } + + return Pair.of(mappedName, shouldPassDesc ? data.mapper.mapDesc(m) : ""); + }) .distinct().collect(Collectors.toList()); if (collection.size() > 1) { @@ -191,7 +205,7 @@ public MemberInfo result() { } return collection.stream().findFirst() - .map(pair -> new MemberInfo(data.mapper.asTrRemapper().map(info.getOwner()), pair.first(), info.getQuantifier(), info.getDesc().isEmpty() ? "" : pair.second())) + .map(pair -> new MemberInfo(data.mapper.asTrRemapper().map(info.getOwner()), pair.first(), info.getQuantifier(), info.getQuantifier().equals("*") ? "" : pair.second())) .orElse(info); } } diff --git a/src/test/java/net/fabricmc/tinyremapper/extension/mixin/integration/MixinIntegrationTest.java b/src/test/java/net/fabricmc/tinyremapper/extension/mixin/integration/MixinIntegrationTest.java index 9dbcbc7e..576f768c 100644 --- a/src/test/java/net/fabricmc/tinyremapper/extension/mixin/integration/MixinIntegrationTest.java +++ b/src/test/java/net/fabricmc/tinyremapper/extension/mixin/integration/MixinIntegrationTest.java @@ -41,8 +41,10 @@ import net.fabricmc.tinyremapper.OutputConsumerPath; import net.fabricmc.tinyremapper.TinyRemapper; import net.fabricmc.tinyremapper.extension.mixin.MixinExtension; +import net.fabricmc.tinyremapper.extension.mixin.integration.mixins.AmbiguousRemappedNameMixin; import net.fabricmc.tinyremapper.extension.mixin.integration.mixins.NonObfuscatedOverrideMixin; import net.fabricmc.tinyremapper.extension.mixin.integration.mixins.WildcardTargetMixin; +import net.fabricmc.tinyremapper.extension.mixin.integration.targets.AmbiguousRemappedNameTarget; import net.fabricmc.tinyremapper.extension.mixin.integration.targets.NonObfuscatedOverrideTarget; import net.fabricmc.tinyremapper.extension.mixin.integration.targets.WildcardTarget; @@ -76,6 +78,19 @@ public void remapInvokeNonObfuscatedOverride() throws IOException { assertTrue(remapped.contains("@Lorg/spongepowered/asm/mixin/injection/At;(value=\"INVOKE\", target=\"Lcom/example/Obfuscated;addAll(Ljava/util/Collection;)Z\"")); } + @Test + public void remapAmbiuousRemappedName() throws IOException { + String remapped = remap(AmbiguousRemappedNameTarget.class, AmbiguousRemappedNameMixin.class, out -> { + String fqn = "net/fabricmc/tinyremapper/extension/mixin/integration/targets/AmbiguousRemappedNameTarget"; + out.acceptClass(fqn, "com/example/Remapped"); + out.acceptMethod(new IMappingProvider.Member(fqn, "addString", "(Ljava/lang/String;)V"), "add"); + out.acceptMethod(new IMappingProvider.Member(fqn, "addList", "(Ljava/util/List;)V"), "add"); + }); + + // full signature is used to disambiguate names + assertTrue(remapped.contains("@Lorg/spongepowered/asm/mixin/injection/Inject;(method={\"add(Ljava/lang/String;)V\"")); + } + private String remap(Class target, Class mixin, IMappingProvider mappings) throws IOException { Path classpath = createJar(target); Path input = createJar(mixin); diff --git a/src/test/java/net/fabricmc/tinyremapper/extension/mixin/integration/mixins/AmbiguousRemappedNameMixin.java b/src/test/java/net/fabricmc/tinyremapper/extension/mixin/integration/mixins/AmbiguousRemappedNameMixin.java new file mode 100644 index 00000000..d1482500 --- /dev/null +++ b/src/test/java/net/fabricmc/tinyremapper/extension/mixin/integration/mixins/AmbiguousRemappedNameMixin.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2016, 2018, Player, asie + * Copyright (c) 2026, FabricMC + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package net.fabricmc.tinyremapper.extension.mixin.integration.mixins; + +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +import net.fabricmc.tinyremapper.extension.mixin.integration.targets.AmbiguousRemappedNameTarget; + +@Mixin(AmbiguousRemappedNameTarget.class) +public class AmbiguousRemappedNameMixin { + @Inject(method = "addString", at = @At("HEAD")) + private void injectAddString(String string, CallbackInfo ci) { + } +} diff --git a/src/test/java/net/fabricmc/tinyremapper/extension/mixin/integration/targets/AmbiguousRemappedNameTarget.java b/src/test/java/net/fabricmc/tinyremapper/extension/mixin/integration/targets/AmbiguousRemappedNameTarget.java new file mode 100644 index 00000000..ec381f2d --- /dev/null +++ b/src/test/java/net/fabricmc/tinyremapper/extension/mixin/integration/targets/AmbiguousRemappedNameTarget.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2016, 2018, Player, asie + * Copyright (c) 2026, FabricMC + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + */ + +package net.fabricmc.tinyremapper.extension.mixin.integration.targets; + +import java.util.List; + +public class AmbiguousRemappedNameTarget { + public void addString(String string) { + } + + public void addList(List list) { + } +}