Fix wrong contract assumption
Currently SamAdapterOverridabilityCondition can be called even for incompatible descriptors #KT-10486 Fixed
This commit is contained in:
+6
@@ -21,6 +21,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.kotlin.descriptors.*;
|
||||
import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl;
|
||||
import org.jetbrains.kotlin.resolve.ExternalOverridabilityCondition;
|
||||
import org.jetbrains.kotlin.resolve.OverridingUtil;
|
||||
import org.jetbrains.kotlin.types.KotlinType;
|
||||
import org.jetbrains.kotlin.types.TypeSubstitutor;
|
||||
import org.jetbrains.kotlin.types.TypeUtils;
|
||||
@@ -45,6 +46,11 @@ public class SamAdapterOverridabilityCondition implements ExternalOverridability
|
||||
return subOriginal == null ? Result.UNKNOWN : Result.INCOMPATIBLE; // DECLARATION can override anything
|
||||
}
|
||||
|
||||
OverridingUtil.OverrideCompatibilityInfo basicResult = OverridingUtil.DEFAULT
|
||||
.isOverridableByWithoutExternalConditions(superDescriptor, subDescriptor, /* checkReturnType = */ false);
|
||||
|
||||
if (basicResult.getResult() != OverridingUtil.OverrideCompatibilityInfo.Result.OVERRIDABLE) return Result.UNKNOWN;
|
||||
|
||||
// inheritor if SYNTHESIZED can override inheritor of SYNTHESIZED if their originals have same erasure
|
||||
return equalErasure(superOriginal, subOriginal) ? Result.UNKNOWN : Result.INCOMPATIBLE;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package test;
|
||||
|
||||
import kotlin.Unit;
|
||||
import kotlin.jvm.functions.Function0;
|
||||
|
||||
public final class DifferentParametersCount {
|
||||
public static class A {
|
||||
static public void foo(Runnable x, int y) {}
|
||||
}
|
||||
|
||||
public static class B extends A {
|
||||
// SAM adapter should not override A.foo
|
||||
static public void foo(Runnable x) {}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package test
|
||||
|
||||
public final class DifferentParametersCount {
|
||||
public constructor DifferentParametersCount()
|
||||
|
||||
public open class A {
|
||||
public constructor A()
|
||||
|
||||
// Static members
|
||||
public final /*synthesized*/ fun foo(/*0*/ p0: (() -> kotlin.Unit)!, /*1*/ p1: kotlin.Int): kotlin.Unit
|
||||
public open fun foo(/*0*/ p0: java.lang.Runnable!, /*1*/ p1: kotlin.Int): kotlin.Unit
|
||||
}
|
||||
|
||||
public open class B : test.DifferentParametersCount.A {
|
||||
public constructor B()
|
||||
|
||||
// Static members
|
||||
public final /*synthesized*/ fun foo(/*0*/ p0: (() -> kotlin.Unit)!): kotlin.Unit
|
||||
public final override /*1*/ /*fake_override*/ fun foo(/*0*/ p0: (() -> kotlin.Unit)!, /*1*/ p1: kotlin.Int): kotlin.Unit
|
||||
public open fun foo(/*0*/ p0: java.lang.Runnable!): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun foo(/*0*/ p0: java.lang.Runnable!, /*1*/ p1: kotlin.Int): kotlin.Unit
|
||||
}
|
||||
}
|
||||
@@ -1344,6 +1344,12 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
|
||||
doTestCompiledJava(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("DifferentParametersCount.java")
|
||||
public void testDifferentParametersCount() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledJava/sam/DifferentParametersCount.java");
|
||||
doTestCompiledJava(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("FilenameFilter.java")
|
||||
public void testFilenameFilter() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/loadJava/compiledJava/sam/FilenameFilter.java");
|
||||
|
||||
Reference in New Issue
Block a user