Skip to content

Commit 66aab4f

Browse files
committed
Don't assume the order of the LVT
1 parent 0f73c12 commit 66aab4f

File tree

5 files changed

+9
-7
lines changed

5 files changed

+9
-7
lines changed

src/main/kotlin/platform/mixin/handlers/RedirectInjectorHandler.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,19 +248,20 @@ class RedirectInjectorHandler : InjectorAnnotationHandler() {
248248
parameters += Parameter("instance", Type.getObjectType(firstMatch.owner).toPsiType(elementFactory))
249249
}
250250

251+
val sortedLocals = sourceClassAndMethod?.method?.localVariables?.sortedBy { it.index }
251252
if (signature != null) {
252253
signature.second
253254
.asSequence()
254255
.withIndex()
255256
.mapTo(parameters) { (index, type) ->
256257
val i = if (firstMatch.opcode == Opcodes.INVOKESTATIC) index else index + 1
257-
val name = sourceClassAndMethod.method.localVariables?.getOrNull(i)?.name?.toJavaIdentifier()
258+
val name = sortedLocals?.getOrNull(i)?.name?.toJavaIdentifier()
258259
sanitizedParameter(type, name, name != null)
259260
}
260261
} else {
261262
Type.getArgumentTypes(firstMatch.desc).withIndex().mapTo(parameters) { (index, type) ->
262263
val i = if (firstMatch.opcode == Opcodes.INVOKESTATIC) index else index + 1
263-
val name = sourceClassAndMethod?.method?.localVariables?.getOrNull(i)?.name?.toJavaIdentifier()
264+
val name = sortedLocals?.getOrNull(i)?.name?.toJavaIdentifier()
264265
sanitizedParameter(type.toPsiType(elementFactory), name, name != null)
265266
}
266267
}

src/main/kotlin/platform/mixin/handlers/mixinextras/MixinExtrasInjectorAnnotationHandler.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -315,16 +315,17 @@ abstract class MixinExtrasInjectorAnnotationHandler : InjectorAnnotationHandler(
315315
sourceClassAndMethod.clazz,
316316
annotation.project,
317317
)
318+
val sortedLocals = sourceClassAndMethod?.method?.localVariables?.sortedBy { it.index }
318319
if (genericParams != null) {
319320
genericParams.withIndex().mapTo(parameters) { (index, type) ->
320321
val i = if (insn.opcode == Opcodes.INVOKESTATIC) index else index + 1
321-
val name = sourceClassAndMethod.method.localVariables?.getOrNull(i)?.name?.toJavaIdentifier()
322+
val name = sortedLocals?.getOrNull(i)?.name?.toJavaIdentifier()
322323
sanitizedParameter(type, name, name != null)
323324
}
324325
} else {
325326
Type.getArgumentTypes(insn.desc).withIndex().mapTo(parameters) { (index, type) ->
326327
val i = if (insn.opcode == Opcodes.INVOKESTATIC) index else index + 1
327-
val name = sourceClassAndMethod?.method?.localVariables?.getOrNull(i)?.name?.toJavaIdentifier()
328+
val name = sortedLocals?.getOrNull(i)?.name?.toJavaIdentifier()
328329
sanitizedParameter(type.toPsiType(elementFactory), name, name != null)
329330
}
330331
}

src/main/kotlin/platform/mixin/inspection/shadow/ShadowParameterNameInspection.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class ShadowParameterNameInspection : MixinInspection() {
4949
return
5050
}
5151
val thisLocals = if (target.classAndMethod.method.hasAccess(Opcodes.ACC_STATIC)) 0 else 1
52-
val targetLocals = target.classAndMethod.method.localVariables?.drop(thisLocals) ?: return
52+
val targetLocals = target.classAndMethod.method.localVariables?.drop(thisLocals)?.sortedBy { it.index } ?: return
5353

5454
val method = annotation.parent?.parent as? PsiMethod ?: return
5555
for ((param, targetLocal) in method.parameterList.parameters.zip(targetLocals)) {

src/main/kotlin/platform/mixin/util/LocalInfo.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class LocalInfo(
6161
}
6262
for (argType in Type.getArgumentTypes(methodNode.desc)) {
6363
val hasNamedArguments = module.fabricMixinCompatibility?.let { it >= 17000 } == true
64-
val localName = methodNode.localVariables?.getOrNull(index)?.name
64+
val localName = methodNode.localVariables?.find { it.index == index }?.name
6565
val name = if (localName != null && hasNamedArguments) {
6666
localName
6767
} else {

src/main/kotlin/platform/mixin/util/LocalVariables.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ object LocalVariables {
451451

452452
// Initialise method arguments
453453
for ((index, argType) in Type.getArgumentTypes(method.desc).withIndex()) {
454-
val localName = method.localVariables?.getOrNull(index + staticOffset)?.name
454+
val localName = method.localVariables?.find { it.index == index + staticOffset }?.name
455455
val name = if (localName == null || !settings.namedParameters) {
456456
"arg$index"
457457
} else {

0 commit comments

Comments
 (0)