Skip to content

Calls to static @Invoker methods with dummy body cause "unreachable code" warnings #2284

Open
@TheRealWormbo

Description

@TheRealWormbo

Minecraft Development for IntelliJ plugin version

2024.1-1.7.4

IntelliJ version

2024.1

Operating System

Linux Mint 21.1

Target platform

Mixins

Description of the bug

Mixins that define an @Invoker for a static target method are required to provide a body for the mixin method, but these methods are usually implemented to always throw an exception, for example:

@Mixin(CriteriaTriggers.class)
public interface CriteriaTriggersAccessor {
	@Invoker("register")
	static <T extends CriterionTrigger<?>> T botania_register(T thing) {
		throw new IllegalStateException();
	}
}

The target method (net.minecraft.advancements.CriteriaTriggers#register) usually completes without throwing an exception. However, code using that invoker method causes following lines to be reported as "unreachable code" by IntelliJ:

public class BotaniaCriteriaTriggers {
	public static void init() {
		CriteriaTriggersAccessor.botania_register(AlfheimPortalTrigger.INSTANCE);
		CriteriaTriggersAccessor.botania_register(CorporeaRequestTrigger.INSTANCE); // unreachable code from here
		CriteriaTriggersAccessor.botania_register(GaiaGuardianNoArmorTrigger.INSTANCE);
		CriteriaTriggersAccessor.botania_register(RelicBindTrigger.INSTANCE);
		CriteriaTriggersAccessor.botania_register(UseItemSuccessTrigger.INSTANCE);
		CriteriaTriggersAccessor.botania_register(ManaBlasterTrigger.INSTANCE);
		CriteriaTriggersAccessor.botania_register(LokiPlaceTrigger.INSTANCE);
		CriteriaTriggersAccessor.botania_register(AlfheimPortalBreadTrigger.INSTANCE);
	}
}

(Code from Botania repository: https://github.com/VazkiiMods/Botania classes vazkii.botania.mixin.CriteriaTriggersAccessor and vazkii.botania.common.advancements.BotaniaCriteriaTriggers from the Xplat module, targeting Minecraft 1.20.1)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions