Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect UnresolvedLocalCapture inspection (using Mixin Extras @Local) #2372

Open
Jamalam360 opened this issue Sep 11, 2024 · 4 comments
Open

Comments

@Jamalam360
Copy link

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;
}
@Earthcomputer
Copy link
Member

Please provide the actual testcase, pseudocode is useless

@Jamalam360
Copy link
Author

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());
    }

@Earthcomputer
Copy link
Member

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

@Jamalam360
Copy link
Author

Here you go, contains the superfluous stuff like log statements 🙃

https://hst.sh/uqayoloqeg.properties

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants