Files
codeql/java/ql/integration-tests/posix-only/kotlin/kotlin-interface-inherited-default/User.java
Chris Smowton 14b8892ced Don't create interface forwarders for other interfaces, and target super accesses correctly
Intermediate interfaces don't need interface forwarders, since the Kotlin compiler won't try to make them non-abstract by synthesising methods.

Super references should always target an immediate superclass, not the ancestor containing the intended implementation.
2022-10-19 15:37:06 +01:00

26 lines
763 B
Java

public class User {
public static void sink(int x) { }
// Real is compiled with synthetic interface method forwarders, so it appears from a Java perspective to override the interface Test.
// RealNoForwards is compiled with -Xjvm-default=all, meaning real Java 8 default interface methods are used, no synthetic forwarders
// are created, and call resolution should go straight to the default.
// RealIndirect is similar to Real, except it inherits its methods indirectly via MiddleInterface.
public static void test(Real r1, RealNoForwards r2, RealIndirect r3) {
sink(r1.f());
sink(r1.g(2));
sink(r1.getX());
sink(r2.f());
sink(r2.g(5));
sink(r2.getX());
sink(r3.f());
sink(r3.g(8));
sink(r3.getX());
}
}