Sealed class: handle the case with actual type alias #KT-26141 Fixed

Before this commit, class super-type could be sealed only in the case
it's the class we are inside or in the same file with.
However, it's quite possible for the expect sealed class
to be implemented by typealias.
So in this commit we allow class super-type to be sealed
if it's typealias expansion we are inside.
This commit is contained in:
Mikhail Glukhikh
2018-09-05 13:25:49 +03:00
parent 56d89266d4
commit bae92f3a33
2 changed files with 14 additions and 2 deletions
@@ -40,7 +40,9 @@ import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
import org.jetbrains.kotlin.resolve.calls.results.OverloadResolutionResults;
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.kotlin.resolve.calls.util.CallMaker;
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
import org.jetbrains.kotlin.resolve.lazy.ForceResolveUtil;
import org.jetbrains.kotlin.resolve.multiplatform.ExpectedActualResolver;
import org.jetbrains.kotlin.resolve.scopes.*;
import org.jetbrains.kotlin.types.*;
import org.jetbrains.kotlin.types.expressions.ExpressionTypingServices;
@@ -497,6 +499,16 @@ public class BodyResolver {
parentEnumOrSealed = new HashSet<>();
}
parentEnumOrSealed.add(currentDescriptor.getTypeConstructor());
if (currentDescriptor.isExpect()) {
List<MemberDescriptor> actualDescriptors = ExpectedActualResolver.INSTANCE.findCompatibleActualForExpected(
currentDescriptor, DescriptorUtilsKt.getModule( currentDescriptor)
);
for (MemberDescriptor actualDescriptor: actualDescriptors) {
if (actualDescriptor instanceof TypeAliasDescriptor) {
parentEnumOrSealed.add(((TypeAliasDescriptor) actualDescriptor).getExpandedType().getConstructor());
}
}
}
}
}
}
@@ -3,8 +3,8 @@
// FILE: common.kt
expect sealed class Presence {
object Online: <!JVM:SEALED_SUPERTYPE!>Presence<!>
object Offline: <!JVM:SEALED_SUPERTYPE!>Presence<!>
object Online: Presence
object Offline: Presence
}
// MODULE: m2-jvm(m1-common)