Skip to content

Commit

Permalink
Relax the invokespecial lookup
Browse files Browse the repository at this point in the history
Account for the fact that invokespecial dispatches mostly dynamically
for super method calls
  • Loading branch information
ogolberg authored Apr 16, 2024
1 parent fa1e906 commit c69f3ff
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
6 changes: 3 additions & 3 deletions core/src/main/kotlin/com/toasttab/expediter/Expediter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,9 @@ private class MemberWithDeclaringType(
)

private fun ResolvedTypeHierarchy.CompleteTypeHierarchy.filterToAccessType(access: MemberAccess): Sequence<Type> {
return if (access is MemberAccess.MethodAccess && access.accessType == MethodAccessType.SPECIAL) {
// invokespecial dispatches statically, i.e. the method must be declared on the target type;
// it is used to invoke constructors, super methods, and private methods
return if (access is MemberAccess.MethodAccess && access.accessType == MethodAccessType.SPECIAL && access.ref.isConstructor()) {
// when invoking constructors, invokespecial dispatches statically
// when invoking super methods, invokespecial dispatches mostly dynamically
sequenceOf(type)
} else {
// fields and methods, except for constructors can be declared on any type in the hierarchy
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
import java.lang.invoke.MethodType;
import java.lang.invoke.VarHandle;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.SortedSet;

public class CallerNegative {
public class CallerNegative extends LinkedHashMap {
private int x;

void arrayCloneIsOk() {
Expand Down Expand Up @@ -86,4 +87,9 @@ void varHandle() throws Throwable {

vh.get(new int[0]);
}

void superSuperCallOk() {
// `invokespecial LinkedHashMap.remove(Object)` should be ok even though `remove` is declared on `HashMap`
super.remove(new Object());
}
}

0 comments on commit c69f3ff

Please sign in to comment.