Fix unique fields conflicting where they shouldn't (#92)

* Fix unique fields crashing when staticness mismatches an existing field

Fixes SpongePowered/Mixin#576

* Fix mismatching mixin fields silently being dropped

Allowing them to be included will throw a VerifyError
This commit is contained in:
Chocohead authored and GitHub committed 2023-02-13 15:15:56 +00:00
1 parent f466542370
commit e2c9aa449c
1 file changed
+8 -5
@@ -628,11 +628,6 @@ class MixinPreProcessorStandard {
mixinField.name = field.renameTo(target.name);
}
if (!Bytecode.compareFlags(mixinField, target, Opcodes.ACC_STATIC)) {
throw new InvalidMixinException(this.mixin, String.format("STATIC modifier of @Shadow field %s in %s does not match the target",
mixinField.name, this.mixin));
}
if (field.isUnique()) {
if ((mixinField.access & (Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED)) != 0) {
String uniqueName = context.getUniqueName(mixinField);
@@ -653,6 +648,14 @@ class MixinPreProcessorStandard {
iter.remove();
continue;
} else if (!Bytecode.compareFlags(mixinField, target, Opcodes.ACC_STATIC)) {
if (isShadow) {
throw new InvalidMixinException(this.mixin, String.format("STATIC modifier of @Shadow field %s in %s does not match the target",
mixinField.name, this.mixin));
} else {
throw new InvalidMixinException(this.mixin, String.format("Field %s in %s conflicts with %sstatic field in the target (%s)",
mixinField.name, mixin, Bytecode.isStatic(target) ? "" : "non-", context.getTarget()));
}
}
// Check that the shadow field has a matching descriptor