Skip to content

Commit

Permalink
Set the bridge bit on the synthetic overload methods
Browse files Browse the repository at this point in the history
  • Loading branch information
JakeWharton committed Jan 28, 2019
1 parent d579a91 commit ed92727
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.jakewharton.overloadreturn.compiler

import org.objectweb.asm.ClassReader
import org.objectweb.asm.ClassWriter
import org.objectweb.asm.Opcodes.ACC_BRIDGE
import org.objectweb.asm.Opcodes.ACC_STATIC
import org.objectweb.asm.Opcodes.ACC_SYNTHETIC
import org.objectweb.asm.Opcodes.ALOAD
Expand Down Expand Up @@ -42,8 +43,8 @@ data class ClassInfo(
val argumentTypes = Type.getArgumentTypes(target.descriptor)
val newDescriptor = Type.getMethodDescriptor(target.returnOverload, *argumentTypes)

writer.visitMethod(target.access.withFlag(ACC_SYNTHETIC), target.name, newDescriptor,
target.signature, target.exceptions).apply {
writer.visitMethod(target.access.withFlags(ACC_BRIDGE, ACC_SYNTHETIC), target.name,
newDescriptor, target.signature, target.exceptions).apply {
visitCode()

var localIndex = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ internal fun Type.toReturnInstruction() = when (this) {
internal infix fun Int.isFlagIn(value: Int) = (value and this) != 0
internal infix fun Int.isNotFlagIn(value: Int) = (value and this) == 0

internal fun Int.withFlag(flag: Int) = this or flag
internal fun Int.withFlags(flag1: Int, flag2: Int) = this or flag1 or flag2
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ class OverloadReturnCompilerTest {
MAXSTACK = 1
MAXLOCALS = 1
// access flags 0x1001
public synthetic method()V
// access flags 0x1041
public synthetic bridge method()V
ALOAD 0
INVOKEVIRTUAL com/example/Test.method ()I
POP
Expand Down Expand Up @@ -141,8 +141,8 @@ class OverloadReturnCompilerTest {
MAXSTACK = 1
MAXLOCALS = 0
// access flags 0x1009
public static synthetic method()V
// access flags 0x1049
public static synthetic bridge method()V
INVOKESTATIC com/example/Test.method ()I
POP
RETURN
Expand Down Expand Up @@ -210,8 +210,8 @@ class OverloadReturnCompilerTest {
MAXSTACK = 1
MAXLOCALS = 1
// access flags 0x1001
public synthetic method()Ljava/lang/CharSequence;
// access flags 0x1041
public synthetic bridge method()Ljava/lang/CharSequence;
ALOAD 0
INVOKEVIRTUAL com/example/Test.method ()Ljava/lang/String;
ARETURN
Expand Down Expand Up @@ -278,8 +278,8 @@ class OverloadReturnCompilerTest {
MAXSTACK = 1
MAXLOCALS = 0
// access flags 0x1009
public static synthetic method()Ljava/lang/CharSequence;
// access flags 0x1049
public static synthetic bridge method()Ljava/lang/CharSequence;
INVOKESTATIC com/example/Test.method ()Ljava/lang/String;
ARETURN
MAXSTACK = 1
Expand Down Expand Up @@ -355,8 +355,8 @@ class OverloadReturnCompilerTest {
MAXSTACK = 12
MAXLOCALS = 12
// access flags 0x1001
public synthetic method(ZBCDFIJSLjava/lang/Object;)Ljava/lang/CharSequence;
// access flags 0x1041
public synthetic bridge method(ZBCDFIJSLjava/lang/Object;)Ljava/lang/CharSequence;
ALOAD 0
ILOAD 1
ILOAD 2
Expand Down

0 comments on commit ed92727

Please sign in to comment.