Fix AssertionError in CodegenUtil.getDelegates
Change getAllOverriddenDescriptors contracti, now it returns original (not substituted) descriptors without any duplicates. First of all it's necessary in CodegenUtil.getDelegates to avoid duplicates (see assertion there), but also it's convenient for all other usages of this method #KT-8154 Fixed
This commit is contained in:
@@ -71,8 +71,7 @@ object CodegenUtil {
|
||||
}
|
||||
|
||||
private fun doesOverride(overrideCandidate: CallableMemberDescriptor, overriddenDescriptor: CallableMemberDescriptor) =
|
||||
(listOf(overrideCandidate) + DescriptorUtils.getAllOverriddenDescriptors(overrideCandidate))
|
||||
.map(CallableMemberDescriptor::getOriginal)
|
||||
(listOf(overrideCandidate.original) + DescriptorUtils.getAllOverriddenDescriptors(overrideCandidate))
|
||||
.contains(overriddenDescriptor.original)
|
||||
|
||||
@JvmStatic
|
||||
|
||||
@@ -1075,7 +1075,7 @@ public class KotlinTypeMapper {
|
||||
|
||||
for (FunctionDescriptor overridden : getAllOverriddenDescriptors(descriptor)) {
|
||||
//noinspection ConstantConditions
|
||||
if (!KotlinBuiltIns.isPrimitiveType(overridden.getOriginal().getReturnType())) return true;
|
||||
if (!KotlinBuiltIns.isPrimitiveType(overridden.getReturnType())) return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
interface A<T> {
|
||||
fun foo(): T
|
||||
}
|
||||
|
||||
interface B<T> : A<T>
|
||||
|
||||
class BImpl<T>(a: A<T>) : B<T>, A<T> by a
|
||||
|
||||
fun box(): String {
|
||||
val b: B<String> = BImpl(object : A<String> {
|
||||
override fun foo() = "OK"
|
||||
})
|
||||
|
||||
if (b.foo() != "OK") return "fail 1"
|
||||
|
||||
val a: A<String> = b
|
||||
|
||||
return a.foo()
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
interface A<T> {
|
||||
fun foo()
|
||||
}
|
||||
|
||||
interface B<T> : A<T> {
|
||||
fun bar()
|
||||
}
|
||||
|
||||
class BImpl<T>(a: A<T>) : B<T>, A<T> by a {
|
||||
override fun bar() { throw UnsupportedOperationException() }
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package
|
||||
|
||||
public interface A</*0*/ T> {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public abstract fun foo(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public interface B</*0*/ T> : A<T> {
|
||||
public abstract fun bar(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public abstract override /*1*/ /*fake_override*/ fun foo(): kotlin.Unit
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public final class BImpl</*0*/ T> : B<T>, A<T> {
|
||||
public constructor BImpl</*0*/ T>(/*0*/ a: A<T>)
|
||||
public open override /*1*/ fun bar(): kotlin.Unit
|
||||
public open override /*2*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*2*/ /*delegation*/ fun foo(): kotlin.Unit
|
||||
public open override /*2*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*2*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -5748,6 +5748,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt8154.kt")
|
||||
public void testKt8154() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegation/kt8154.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/delegation/clashes")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
@@ -5655,6 +5655,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegation/delegationToVal.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("kt8154.kt")
|
||||
public void testKt8154() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/delegation/kt8154.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/destructuringDeclInLambdaParam")
|
||||
|
||||
@@ -469,6 +469,9 @@ public class DescriptorUtils {
|
||||
return classDescriptor.getModality() != Modality.FINAL || classDescriptor.getKind() == ClassKind.ENUM_CLASS;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return original (not substituted) descriptors without any duplicates
|
||||
*/
|
||||
@NotNull
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <D extends CallableDescriptor> Set<D> getAllOverriddenDescriptors(@NotNull D f) {
|
||||
@@ -481,7 +484,7 @@ public class DescriptorUtils {
|
||||
if (result.contains(current)) return;
|
||||
for (CallableDescriptor callableDescriptor : current.getOriginal().getOverriddenDescriptors()) {
|
||||
@SuppressWarnings("unchecked")
|
||||
D descriptor = (D) callableDescriptor;
|
||||
D descriptor = (D) callableDescriptor.getOriginal();
|
||||
collectAllOverriddenDescriptors(descriptor, result);
|
||||
result.add(descriptor);
|
||||
}
|
||||
|
||||
@@ -119,7 +119,7 @@ public class OverridingUtil {
|
||||
|
||||
CallableDescriptor originalG = g.getOriginal();
|
||||
for (D overriddenFunction : DescriptorUtils.getAllOverriddenDescriptors(f)) {
|
||||
if (DescriptorEquivalenceForOverrides.INSTANCE.areEquivalent(originalG, overriddenFunction.getOriginal())) return true;
|
||||
if (DescriptorEquivalenceForOverrides.INSTANCE.areEquivalent(originalG, overriddenFunction)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user