Skip to content

Commit

Permalink
Correct an edge case in the invokespecial lookup
Browse files Browse the repository at this point in the history
Invokespecial always dispatches statically, regardless of whether it's
calling a constructor or something else
  • Loading branch information
ogolberg authored Mar 7, 2024
1 parent 03681a5 commit 0f42b02
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 3 deletions.
5 changes: 3 additions & 2 deletions core/src/main/kotlin/com/toasttab/expediter/Expediter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,9 @@ private class MemberWithDeclaringType(
)

private fun <M : MemberType> ResolvedTypeHierarchy.CompleteTypeHierarchy.filterToAccessType(access: MemberAccess<M>): Sequence<Type> {
return if (access is MemberAccess.MethodAccess && access.accessType == MethodAccessType.SPECIAL && access.ref.isConstructor()) {
// constructors must always be declared by the type being constructed
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
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
@@ -1,5 +1,7 @@
package com.toasttab.expediter.test;

public class Base {
public class Base extends BaseBase {
public int w;

public void supersuper() { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.toasttab.expediter.test;

public class BaseBase {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.toasttab.expediter.test;

public class BaseBase {
public void supersuper() { }
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,8 @@ void missingTypeMethodArg() {
boolean missingTypeInstanceof(Object o) {
return o instanceof ParamParam[];
}

void superMethodMoved() {
super.supersuper();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,16 @@ class ExpediterIntegrationTest {
)
),

Issue.MissingMember(
"com/toasttab/expediter/test/caller/Caller",
MemberAccess.MethodAccess(
"com/toasttab/expediter/test/Base",
null,
MemberSymbolicReference("supersuper", "()V"),
MethodAccessType.SPECIAL
)
),

Issue.AccessInstanceMemberStatically(
"com/toasttab/expediter/test/caller/Caller",
MemberAccess.MethodAccess(
Expand Down

0 comments on commit 0f42b02

Please sign in to comment.