Avoid assertion in bridges-generation for light classes

^KT-11656
This commit is contained in:
Denis Zharkov
2019-01-11 12:21:10 +03:00
parent e0ff7281b4
commit 5ec93f2718
9 changed files with 69 additions and 4 deletions
@@ -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]