Avoid assertion in bridges-generation for light classes
^KT-11656
This commit is contained in:
@@ -56,7 +56,7 @@ fun <Function : FunctionHandle, Signature> generateBridges(
|
||||
// into some of the super-classes and will be inherited in this class
|
||||
if (fake && function.getOverridden().none { it.isAbstract }) return setOf()
|
||||
|
||||
val implementation = findConcreteSuperDeclaration(function)
|
||||
val implementation = findConcreteSuperDeclaration(function) ?: return setOf()
|
||||
|
||||
val bridgesToGenerate = findAllReachableDeclarations(function).mapTo(LinkedHashSet<Signature>(), signature)
|
||||
|
||||
@@ -94,7 +94,7 @@ fun <Function : FunctionHandle> findAllReachableDeclarations(function: Function)
|
||||
* Given a concrete function, finds an implementation (a concrete declaration) of this function in the supertypes.
|
||||
* The implementation is guaranteed to exist because if it wouldn't, the given function would've been abstract
|
||||
*/
|
||||
fun <Function : FunctionHandle> findConcreteSuperDeclaration(function: Function): Function {
|
||||
fun <Function : FunctionHandle> findConcreteSuperDeclaration(function: Function): Function? {
|
||||
require(!function.isAbstract, { "Only concrete functions have implementations: $function" })
|
||||
|
||||
if (function.isDeclaration) return function
|
||||
@@ -118,7 +118,11 @@ fun <Function : FunctionHandle> findConcreteSuperDeclaration(function: Function)
|
||||
|
||||
val concreteRelevantDeclarations = result.filter { !it.isAbstract && it.mayBeUsedAsSuperImplementation }
|
||||
if (concreteRelevantDeclarations.size != 1) {
|
||||
error("Concrete fake override $function should have exactly one concrete super-declaration: $concreteRelevantDeclarations")
|
||||
if (!function.mightBeIncorrectCode) {
|
||||
error("Concrete fake override $function should have exactly one concrete super-declaration: $concreteRelevantDeclarations")
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
return concreteRelevantDeclarations[0]
|
||||
|
||||
@@ -153,7 +153,7 @@ private fun <Signature> findSuperImplementationForStubDelegation(
|
||||
state: GenerationState,
|
||||
signatureByDescriptor: (FunctionDescriptor) -> Signature
|
||||
): FunctionDescriptor? {
|
||||
val implementation = findConcreteSuperDeclaration(DescriptorBasedFunctionHandleForJvm(function, state))
|
||||
val implementation = findConcreteSuperDeclaration(DescriptorBasedFunctionHandleForJvm(function, state)) ?: return null
|
||||
|
||||
// Implementation from interface will be generated by common mechanism
|
||||
if (!implementation.mayBeUsedAsSuperImplementation) return null
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
public enum EnumNameOverride implements Bar {
|
||||
;
|
||||
|
||||
private EnumNameOverride() { /* compiled code */ }
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// EnumNameOverride
|
||||
interface Foo {
|
||||
fun name(): String
|
||||
}
|
||||
|
||||
interface Bar : Foo {
|
||||
override fun name() = name
|
||||
var name: String
|
||||
}
|
||||
|
||||
enum class EnumNameOverride : Bar
|
||||
@@ -0,0 +1,9 @@
|
||||
public final class TwoOverrides implements java.lang.Iterable<java.lang.String>, kotlin.collections.Iterable<java.lang.String>, kotlin.jvm.internal.markers.KMappedMarker {
|
||||
@org.jetbrains.annotations.Nullable
|
||||
public java.lang.Void iterator() { /* compiled code */ }
|
||||
|
||||
@org.jetbrains.annotations.Nullable
|
||||
public java.lang.Void iterator() { /* compiled code */ }
|
||||
|
||||
public TwoOverrides() { /* compiled code */ }
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
// TwoOverrides
|
||||
class TwoOverrides : Iterable<String> {
|
||||
override fun iterator() = null
|
||||
|
||||
override fun iterator() = null
|
||||
}
|
||||
+10
@@ -181,6 +181,11 @@ public class CompilerLightClassTestGenerated extends AbstractCompilerLightClassT
|
||||
runTest("compiler/testData/asJava/lightClasses/compilationErrors/AnnotationModifiers.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("EnumNameOverride.kt")
|
||||
public void testEnumNameOverride() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/compilationErrors/EnumNameOverride.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ExpectClass.kt")
|
||||
public void testExpectClass() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/compilationErrors/ExpectClass.kt");
|
||||
@@ -236,6 +241,11 @@ public class CompilerLightClassTestGenerated extends AbstractCompilerLightClassT
|
||||
runTest("compiler/testData/asJava/lightClasses/compilationErrors/TraitClassObjectField.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("TwoOverrides.kt")
|
||||
public void testTwoOverrides() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/compilationErrors/TwoOverrides.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("WrongAnnotations.kt")
|
||||
public void testWrongAnnotations() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/compilationErrors/WrongAnnotations.kt");
|
||||
|
||||
+10
@@ -181,6 +181,11 @@ public class UltraLightClassSanityTestGenerated extends AbstractUltraLightClassS
|
||||
runTest("compiler/testData/asJava/lightClasses/compilationErrors/AnnotationModifiers.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("EnumNameOverride.kt")
|
||||
public void testEnumNameOverride() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/compilationErrors/EnumNameOverride.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ExpectClass.kt")
|
||||
public void testExpectClass() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/compilationErrors/ExpectClass.kt");
|
||||
@@ -236,6 +241,11 @@ public class UltraLightClassSanityTestGenerated extends AbstractUltraLightClassS
|
||||
runTest("compiler/testData/asJava/lightClasses/compilationErrors/TraitClassObjectField.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("TwoOverrides.kt")
|
||||
public void testTwoOverrides() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/compilationErrors/TwoOverrides.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("WrongAnnotations.kt")
|
||||
public void testWrongAnnotations() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/compilationErrors/WrongAnnotations.kt");
|
||||
|
||||
+10
@@ -181,6 +181,11 @@ public class IdeLightClassTestGenerated extends AbstractIdeLightClassTest {
|
||||
runTest("compiler/testData/asJava/lightClasses/compilationErrors/AnnotationModifiers.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("EnumNameOverride.kt")
|
||||
public void testEnumNameOverride() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/compilationErrors/EnumNameOverride.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ExpectClass.kt")
|
||||
public void testExpectClass() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/compilationErrors/ExpectClass.kt");
|
||||
@@ -236,6 +241,11 @@ public class IdeLightClassTestGenerated extends AbstractIdeLightClassTest {
|
||||
runTest("compiler/testData/asJava/lightClasses/compilationErrors/TraitClassObjectField.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("TwoOverrides.kt")
|
||||
public void testTwoOverrides() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/compilationErrors/TwoOverrides.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("WrongAnnotations.kt")
|
||||
public void testWrongAnnotations() throws Exception {
|
||||
runTest("compiler/testData/asJava/lightClasses/compilationErrors/WrongAnnotations.kt");
|
||||
|
||||
Reference in New Issue
Block a user