MinecraftDev icon indicating copy to clipboard operation
MinecraftDev copied to clipboard

Incorrect `UnresolvedLocalCapture` inspection (using Mixin Extras @Local)

Open Jamalam360 opened this issue 1 year ago • 4 comments
trafficstars

Minecraft Development for IntelliJ plugin version

2024.2-1.8.1

IntelliJ version

2024.2.1

Operating System

Linux

Target platform

Fabric

Description of the bug

mcdev says that @Local does not match any or matched multiple local variables in the target method for both @Local parameters in this mixin, but the mixin works fine.

Injector:

@Inject(
	method = "save",
	at = @At(
			value = "INVOKE",
			target = "Lnet/minecraft/nbt/CompoundTag;putInt(Ljava/lang/String;I)V"
	)
)
private void exampleMixin(CompoundTag tag, CallbackInfoReturnable<CompoundTag> cir, @Local WarpPlatePair pair, @Local(ordinal = 1) CompoundTag pairTag) {
// ...
}

Target:

public CompoundTag save(CompoundTag tag) {
  ListTag pairs = new ListTag();
  
  for (WarpPlatePair pair : this.pairs) { // <-- Local I am targetting
	  CompoundTag pairTag = new CompoundTag(); // <-- Local I am targetting
	  pairTag.putInt("id", pair.id());
	  // ...
  }
  // ...
  return tag;
}

Jamalam360 avatar Sep 11 '24 17:09 Jamalam360

Please provide the actual testcase, pseudocode is useless

Earthcomputer avatar Sep 11 '24 18:09 Earthcomputer

It's not really pseudocode -

target:

@Override
public CompoundTag save(CompoundTag tag) {
  ListTag pairs = new ListTag();

  for (WarpPlatePair pair : this.pairs) {
	CompoundTag pairTag = new CompoundTag();
	pairTag.putInt("id", pair.id());
	pairTag.putLong("expiryTime", pair.expiryTime());
	pairs.add(pairTag);
  }

  tag.put("pairs", pairs);
  return tag;
}

injector:

 @Inject(
            method = "save",
            at = @At(
                    value = "INVOKE",
                    target = "Lnet/minecraft/nbt/CompoundTag;putInt(Ljava/lang/String;I)V"
            )
    )
    private void notifier$saveNotifierField(CompoundTag tag, CallbackInfoReturnable<CompoundTag> cir, @Local WarpPlatePair pair, @Local(ordinal = 1) CompoundTag pairTag) {
        pairTag.putBoolean("notifiedOfExpiry", ((WarpPlatePairDuck) (Object) pair).notifier$hasNotifiedOfExpiry());
    }

Jamalam360 avatar Sep 11 '24 18:09 Jamalam360

It matters how the target method was compiled, can you upload the target bytecode?

Earthcomputer avatar Sep 11 '24 18:09 Earthcomputer

Here you go, contains the superfluous stuff like log statements :upside_down_face:

https://hst.sh/uqayoloqeg.properties

Jamalam360 avatar Sep 11 '24 18:09 Jamalam360