LlamaLad7 / MixinExtras

Companion library to SpongePowered Mixin with many custom injectors for a more expressive experience.
MIT License
293 stars 16 forks source link

Targeting lambdas does not work with ME's AP #51

Closed Jonathing closed 9 months ago

Jonathing commented 9 months ago

Title entails.

Trying to build the project with the following (example) annotation generates this error from MixinExtras's Annotation Processor.

@WrapOperation(
    method = "lambda$run$6(Ljava/util/function/Predicate;Ljava/util/function/Predicate;Lnet/minecraft/data/CachedOutput;Ljava/util/Map$Entry;)Ljava/util/concurrent/CompletableFuture;",
    at = @At(
        value = "INVOKE",
        target = "java/util/List.isEmpty()Z"
    )
)
D:\dev\git\minecraft\cryptic-mushroom\registry\src\main\java\com\crypticmushroom\minecraft\registry\coremod\mixin\data\TagsProviderMixin.java:44: error: Unable to locate obfuscation mapping for @WrapOperation target lambda$run$6
    @WrapOperation(
    ^

Vanilla Mixin injectors do not have this problem.

Workaround

This issue can be solved in the short term for projects that need it by manually supplying the method target with the expected SRG obfuscation name.

@WrapOperation(
    method = {
        "lambda$run$6(Ljava/util/function/Predicate;Ljava/util/function/Predicate;Lnet/minecraft/data/CachedOutput;Ljava/util/Map$Entry;)Ljava/util/concurrent/CompletableFuture;",
        "m_252638_(Ljava/util/function/Predicate;Ljava/util/function/Predicate;Lnet/minecraft/data/CachedOutput;Ljava/util/Map$Entry;)Ljava/util/concurrent/CompletableFuture;"
    },
    remap = false,
    at = @At(
        value = "INVOKE",
        target = "java/util/List.isEmpty()Z"
    )
)

Quick Thanks

MixinExtras has been nothing but a blessing for me in many scenarios, and I personally thank you and admire the work you've put into this project.

LlamaLad7 commented 9 months ago

Could you provide either a MRE repo or a link to a project in which you've encountered this so I can reproduce?

Jonathing commented 9 months ago

Here's the goofy Mixin I'm using in my personal project

https://gitlab.com/cryptic-mushroom/minecraft/cryptic-registry/-/blob/1.19.4/src/main/java/com/crypticmushroom/minecraft/registry/coremod/mixin/data/TagsProviderMixin.java?ref_type=heads

Although for debugging this it's probably more practical to write a Mixin where the effects are a lot more obvious

LlamaLad7 commented 9 months ago

Vanilla Mixin injectors do not have this problem.

Swapping out the injector for a Redirect results in the exact same error. This particular lambda likely does not have a mapping due to this patch.

LlamaLad7 commented 9 months ago

Also the stock Mixin AP cannot remap lambdas properly in the first place, you need to use fabric's fork as an AP for that. Note the warning about ItemTagsProviderMixin.

Jonathing commented 9 months ago

Got it. Thanks!