[FIR2IR] Force loading Java SAM from external classes

This commit is contained in:
Mikhail Glukhikh
2020-05-14 14:07:04 +03:00
parent 89a6ecd77d
commit cdac6157a9
12 changed files with 38 additions and 28 deletions
@@ -466,6 +466,9 @@ fun FirClass<*>.irOrigin(firProvider: FirProvider): IrDeclarationOrigin = when {
else -> IrDeclarationOrigin.IR_EXTERNAL_DECLARATION_STUB
}
fun FirClass<*>.getSamIfAny(): FirSimpleFunction? =
declarations.filterIsInstance<FirSimpleFunction>().singleOrNull { it.modality == Modality.ABSTRACT }
val IrType.isSamType: Boolean
get() {
val irClass = classOrNull ?: return false
@@ -180,7 +180,17 @@ class Fir2IrDeclarationStorage(
}
internal fun addDeclarationsToExternalClass(regularClass: FirRegularClass, irClass: IrClass) {
if (regularClass.symbol.classId.packageFqName.startsWith(Name.identifier("kotlin"))) {
if (regularClass.origin == FirDeclarationOrigin.Java) {
val sam = regularClass.getSamIfAny()
if (sam != null) {
val scope = regularClass.buildUseSiteMemberScope(session, scopeSession)!!
scope.processFunctionsByName(sam.name) {
if (it is FirNamedFunctionSymbol && !it.isFakeOverride) {
irClass.declarations += createIrFunction(it.fir, irClass)
}
}
}
} else if (regularClass.symbol.classId.packageFqName.startsWith(Name.identifier("kotlin"))) {
// Note: yet this is necessary only for *Range / *Progression classes
// due to BE optimizations (for lowering) that use their first / last / step members
// TODO: think how to refactor this piece of code and/or merge it with similar Fir2IrVisitor fragment