Match triangle & diamond intersections in FirTypeIntersectionScope
This commit is contained in:
+15
@@ -2651,6 +2651,16 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/definitelyNotNullAndOriginalType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("doubleGenericDiamond.kt")
|
||||
public void testDoubleGenericDiamond() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/doubleGenericDiamond.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("falseIntersection.kt")
|
||||
public void testFalseIntersection() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/falseIntersection.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("flexibleTypeVarAgainstNull.kt")
|
||||
public void testFlexibleTypeVarAgainstNull() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/flexibleTypeVarAgainstNull.kt");
|
||||
@@ -2705,6 +2715,11 @@ public class LazyBodyIsNotTouchedTilContractsPhaseTestGenerated extends Abstract
|
||||
public void testSecondaryConstructorCfg() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/secondaryConstructorCfg.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("transform.kt")
|
||||
public void testTransform() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/transform.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/fir/analysis-tests/testData/resolve/properties")
|
||||
|
||||
+41
@@ -0,0 +1,41 @@
|
||||
FILE: doubleGenericDiamond.kt
|
||||
public abstract interface Left : R|kotlin/Any| {
|
||||
}
|
||||
public abstract interface Right : R|kotlin/Any| {
|
||||
}
|
||||
public final class Bottom : R|Left|, R|Right| {
|
||||
public constructor(): R|Bottom| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
}
|
||||
public abstract interface A<T> : R|kotlin/Any| {
|
||||
public open fun f(): R|T?| {
|
||||
^f Null(null)
|
||||
}
|
||||
|
||||
}
|
||||
public abstract interface B<T : R|Left|> : R|A<T>| {
|
||||
public open override fun f(): R|T?| {
|
||||
^f Null(null)
|
||||
}
|
||||
|
||||
}
|
||||
public abstract class C<T> : R|A<T>| {
|
||||
public constructor<T>(): R|C<T>| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
}
|
||||
public abstract class D<T : R|Right|> : R|C<T>| {
|
||||
public constructor<T : R|Right|>(): R|D<T>| {
|
||||
super<R|C<T>|>()
|
||||
}
|
||||
|
||||
}
|
||||
public final class Z : R|D<Bottom>|, R|B<Bottom>| {
|
||||
public constructor(): R|Z| {
|
||||
super<R|D<Bottom>|>()
|
||||
}
|
||||
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
interface Left
|
||||
interface Right
|
||||
class Bottom : Left, Right
|
||||
|
||||
interface A<T> {
|
||||
fun f(): T? {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
interface B<T : Left> : A<T> {
|
||||
override fun f(): T? {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
abstract class C<T> : A<T>
|
||||
|
||||
abstract class D<T : Right> : C<T>()
|
||||
|
||||
// We should not have intersection override f() in this class
|
||||
class Z : D<Bottom>(), B<Bottom>
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
FILE: falseIntersection.kt
|
||||
public abstract interface A : R|kotlin/Any| {
|
||||
public open fun foo(): R|kotlin/Unit| {
|
||||
}
|
||||
|
||||
}
|
||||
public abstract interface B : R|A| {
|
||||
public open override fun foo(): R|kotlin/Unit| {
|
||||
}
|
||||
|
||||
}
|
||||
public final class C : R|B|, R|A| {
|
||||
public constructor(): R|C| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
interface A {
|
||||
fun foo() {}
|
||||
}
|
||||
|
||||
interface B : A {
|
||||
override fun foo() {}
|
||||
}
|
||||
|
||||
// We should not have intersection override foo() in this class
|
||||
class C : B, A
|
||||
@@ -0,0 +1,160 @@
|
||||
FILE: transform.kt
|
||||
public sealed class CompositeTransformResult<out T : R|kotlin/Any|> : R|kotlin/Any| {
|
||||
protected constructor<out T : R|kotlin/Any|>(): R|CompositeTransformResult<T>| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final class Single<out T : R|kotlin/Any|> : R|CompositeTransformResult<T>| {
|
||||
public constructor<out T : R|kotlin/Any|>(_single: R|T|): R|CompositeTransformResult.Single<T>| {
|
||||
super<R|CompositeTransformResult<T>|>()
|
||||
}
|
||||
|
||||
public final val _single: R|T| = R|<local>/_single|
|
||||
public get(): R|T|
|
||||
|
||||
}
|
||||
|
||||
public final class Multiple<out T : R|kotlin/Any|> : R|CompositeTransformResult<T>| {
|
||||
public constructor<out T : R|kotlin/Any|>(_list: R|kotlin/collections/List<T>|): R|CompositeTransformResult.Multiple<T>| {
|
||||
super<R|CompositeTransformResult<T>|>()
|
||||
}
|
||||
|
||||
public final val _list: R|kotlin/collections/List<T>| = R|<local>/_list|
|
||||
public get(): R|kotlin/collections/List<T>|
|
||||
|
||||
}
|
||||
|
||||
public final companion object Companion : R|kotlin/Any| {
|
||||
private constructor(): R|CompositeTransformResult.Companion| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final fun <T : R|kotlin/Any|> single(t: R|T|): R|CompositeTransformResult.Single<T>| {
|
||||
^single R|SubstitutionOverride</CompositeTransformResult.Single.Single>|<R|T|>(R|<local>/t|)
|
||||
}
|
||||
|
||||
public final fun <T : R|kotlin/Any|> many(l: R|kotlin/collections/List<T>|): R|CompositeTransformResult.Multiple<T>| {
|
||||
^many R|SubstitutionOverride</CompositeTransformResult.Multiple.Multiple>|<R|T|>(R|<local>/l|)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public final val single: R|T|
|
||||
public get(): R|T| {
|
||||
^ ((this@R|/CompositeTransformResult| as R|CompositeTransformResult.Single<*>|).R|SubstitutionOverride</CompositeTransformResult.Single._single: R|CapturedType(*)|>| as R|T|)
|
||||
}
|
||||
|
||||
}
|
||||
public abstract interface FirElement : R|kotlin/Any| {
|
||||
public abstract fun <R, D> accept(visitor: R|FirVisitor<R, D>|, data: R|D|): R|R|
|
||||
|
||||
public open fun accept(visitor: R|FirVisitorVoid|): R|kotlin/Unit| {
|
||||
^accept this@R|/FirElement|.R|/FirElement.accept|<R|kotlin/Unit|, R|kotlin/Nothing?|>(R|<local>/visitor|, Null(null))
|
||||
}
|
||||
|
||||
public abstract fun <E : R|FirElement|, D> transform(visitor: R|FirTransformer<D>|, data: R|D|): R|CompositeTransformResult<E>|
|
||||
|
||||
}
|
||||
public abstract class FirVisitor<out R, in D> : R|kotlin/Any| {
|
||||
public constructor<out R, in D>(): R|FirVisitor<R, D>| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
}
|
||||
public abstract class FirVisitorVoid : R|FirVisitor<kotlin/Unit, kotlin/Nothing?>| {
|
||||
public constructor(): R|FirVisitorVoid| {
|
||||
super<R|FirVisitor<kotlin/Unit, kotlin/Nothing?>|>()
|
||||
}
|
||||
|
||||
}
|
||||
public abstract class FirTransformer<in D> : R|FirVisitor<CompositeTransformResult<FirElement>, D>| {
|
||||
public constructor<in D>(): R|FirTransformer<D>| {
|
||||
super<R|FirVisitor<CompositeTransformResult<FirElement>, D>|>()
|
||||
}
|
||||
|
||||
}
|
||||
public abstract interface FirAnnotationContainer : R|FirElement| {
|
||||
public abstract override fun <R, D> accept(visitor: R|FirVisitor<R, D>|, data: R|D|): R|R|
|
||||
|
||||
}
|
||||
public abstract interface FirStatement : R|FirAnnotationContainer| {
|
||||
public abstract override fun <R, D> accept(visitor: R|FirVisitor<R, D>|, data: R|D|): R|R|
|
||||
|
||||
}
|
||||
public abstract interface FirTypeParameterRefsOwner : R|FirElement| {
|
||||
public abstract override fun <R, D> accept(visitor: R|FirVisitor<R, D>|, data: R|D|): R|R|
|
||||
|
||||
}
|
||||
public abstract interface FirDeclaration : R|FirElement| {
|
||||
public abstract override fun <R, D> accept(visitor: R|FirVisitor<R, D>|, data: R|D|): R|R|
|
||||
|
||||
}
|
||||
public abstract interface FirAnnotatedDeclaration : R|FirDeclaration|, R|FirAnnotationContainer| {
|
||||
public abstract override fun <R, D> accept(visitor: R|FirVisitor<R, D>|, data: R|D|): R|R|
|
||||
|
||||
}
|
||||
public abstract interface FirSymbolOwner<E : R|FirSymbolOwner<E>|, R|FirDeclaration|> : R|FirElement| {
|
||||
public abstract override fun <R, D> accept(visitor: R|FirVisitor<R, D>|, data: R|D|): R|R|
|
||||
|
||||
}
|
||||
public abstract interface FirClassLikeDeclaration<F : R|FirClassLikeDeclaration<F>|> : R|FirAnnotatedDeclaration|, R|FirStatement|, R|FirSymbolOwner<F>| {
|
||||
}
|
||||
public abstract interface FirClass<F : R|FirClass<F>|> : R|FirClassLikeDeclaration<F>|, R|FirStatement|, R|FirTypeParameterRefsOwner| {
|
||||
}
|
||||
private final class FirApplySupertypesTransformer : R|FirTransformer<kotlin/Nothing?>| {
|
||||
public constructor(): R|FirApplySupertypesTransformer| {
|
||||
super<R|FirTransformer<kotlin/Nothing?>|>()
|
||||
}
|
||||
|
||||
}
|
||||
public final fun <F : R|FirClass<F>|> R|F|.runSupertypeResolvePhaseForLocalClass(): R|F| {
|
||||
lval applySupertypesTransformer: R|FirApplySupertypesTransformer| = R|/FirApplySupertypesTransformer.FirApplySupertypesTransformer|()
|
||||
^runSupertypeResolvePhaseForLocalClass this@R|/runSupertypeResolvePhaseForLocalClass|.R|SubstitutionOverride</FirClass.transform: R|CompositeTransformResult<E>|>|<R|F|, R|kotlin/Nothing?|>(R|<local>/applySupertypesTransformer|, Null(null)).R|SubstitutionOverride</CompositeTransformResult.single: R|F|>|
|
||||
}
|
||||
public abstract class FirPureAbstractElement : R|FirElement| {
|
||||
public constructor(): R|FirPureAbstractElement| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
}
|
||||
public abstract interface FirTypedDeclaration : R|FirAnnotatedDeclaration| {
|
||||
public abstract override fun <R, D> accept(visitor: R|FirVisitor<R, D>|, data: R|D|): R|R|
|
||||
|
||||
}
|
||||
public abstract interface FirCallableDeclaration<F : R|FirCallableDeclaration<F>|> : R|FirTypedDeclaration|, R|FirSymbolOwner<F>| {
|
||||
public abstract override fun <R, D> accept(visitor: R|FirVisitor<R, D>|, data: R|D|): R|R|
|
||||
|
||||
}
|
||||
public abstract class FirVariable<F : R|FirVariable<F>|> : R|FirPureAbstractElement|, R|FirCallableDeclaration<F>|, R|FirAnnotatedDeclaration|, R|FirStatement| {
|
||||
public constructor<F : R|FirVariable<F>|>(): R|FirVariable<F>| {
|
||||
super<R|FirPureAbstractElement|>()
|
||||
}
|
||||
|
||||
public abstract override fun <R, D> accept(visitor: R|FirVisitor<R, D>|, data: R|D|): R|R|
|
||||
|
||||
}
|
||||
public abstract class FirWhenExpression : R|kotlin/Any| {
|
||||
public constructor(): R|FirWhenExpression| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public abstract val subjectVariable: R|FirVariable<*>?|
|
||||
public get(): R|FirVariable<*>?|
|
||||
|
||||
}
|
||||
public final class FirRenderer : R|FirVisitorVoid| {
|
||||
public constructor(): R|FirRenderer| {
|
||||
super<R|FirVisitorVoid|>()
|
||||
}
|
||||
|
||||
public final fun foo(expression: R|FirWhenExpression|): R|kotlin/Unit| {
|
||||
lval variable: R|FirVariable<*>?| = R|<local>/expression|.R|/FirWhenExpression.subjectVariable|
|
||||
when () {
|
||||
!=(R|<local>/variable|, Null(null)) -> {
|
||||
R|<local>/variable|.R|/FirElement.accept|(this@R|/FirRenderer|)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
sealed class CompositeTransformResult<out T : Any> {
|
||||
|
||||
class Single<out T : Any>(val _single: T) : CompositeTransformResult<T>()
|
||||
|
||||
class Multiple<out T : Any>(val _list: List<T>) : CompositeTransformResult<T>()
|
||||
|
||||
companion object {
|
||||
fun <T : Any> single(t: T) = Single(t)
|
||||
fun <T : Any> many(l: List<T>) = Multiple(l)
|
||||
}
|
||||
|
||||
val single: T
|
||||
get() = (this as Single<*>)._single as T
|
||||
}
|
||||
|
||||
interface FirElement {
|
||||
fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R
|
||||
|
||||
fun accept(visitor: FirVisitorVoid) = accept(visitor, null)
|
||||
|
||||
fun <E : FirElement, D> transform(visitor: FirTransformer<D>, data: D): CompositeTransformResult<E>
|
||||
}
|
||||
|
||||
abstract class FirVisitor<out R, in D>
|
||||
|
||||
abstract class FirVisitorVoid : FirVisitor<Unit, Nothing?>()
|
||||
|
||||
abstract class FirTransformer<in D> : FirVisitor<CompositeTransformResult<FirElement>, D>()
|
||||
|
||||
interface FirAnnotationContainer : FirElement {
|
||||
abstract override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R
|
||||
}
|
||||
|
||||
interface FirStatement : FirAnnotationContainer {
|
||||
abstract override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R
|
||||
}
|
||||
|
||||
interface FirTypeParameterRefsOwner : FirElement {
|
||||
abstract override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R
|
||||
}
|
||||
|
||||
interface FirDeclaration : FirElement {
|
||||
abstract override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R
|
||||
}
|
||||
|
||||
interface FirAnnotatedDeclaration : FirDeclaration, FirAnnotationContainer {
|
||||
abstract override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R
|
||||
}
|
||||
|
||||
interface FirSymbolOwner<E> : FirElement where E : FirSymbolOwner<E>, E : FirDeclaration {
|
||||
abstract override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R
|
||||
}
|
||||
|
||||
interface FirClassLikeDeclaration<F : FirClassLikeDeclaration<F>> : FirAnnotatedDeclaration, FirStatement, FirSymbolOwner<F>
|
||||
|
||||
interface FirClass<F : FirClass<F>> : FirClassLikeDeclaration<F>, FirStatement, FirTypeParameterRefsOwner
|
||||
|
||||
private class FirApplySupertypesTransformer() : FirTransformer<Nothing?>()
|
||||
|
||||
fun <F : FirClass<F>> F.runSupertypeResolvePhaseForLocalClass(): F {
|
||||
val applySupertypesTransformer = FirApplySupertypesTransformer()
|
||||
return this.transform<F, Nothing?>(applySupertypesTransformer, null).single
|
||||
}
|
||||
|
||||
abstract class FirPureAbstractElement : FirElement
|
||||
|
||||
interface FirTypedDeclaration : FirAnnotatedDeclaration {
|
||||
abstract override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R
|
||||
}
|
||||
|
||||
interface FirCallableDeclaration<F : FirCallableDeclaration<F>> : FirTypedDeclaration, FirSymbolOwner<F> {
|
||||
abstract override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R
|
||||
}
|
||||
|
||||
abstract class FirVariable<F : FirVariable<F>> : FirPureAbstractElement(), FirCallableDeclaration<F>, FirAnnotatedDeclaration, FirStatement {
|
||||
abstract override fun <R, D> accept(visitor: FirVisitor<R, D>, data: D): R
|
||||
}
|
||||
|
||||
abstract class FirWhenExpression {
|
||||
abstract val subjectVariable: FirVariable<*>?
|
||||
}
|
||||
|
||||
class FirRenderer : FirVisitorVoid() {
|
||||
fun foo(expression: FirWhenExpression) {
|
||||
val variable = expression.subjectVariable
|
||||
if (variable != null) {
|
||||
variable.accept(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -23,7 +23,7 @@ FILE: Test.kt
|
||||
}
|
||||
|
||||
public final fun test(): R|kotlin/String| {
|
||||
^test this@R|/LightClassWrapper|.R|/LightClassWrapper.typeParameters|.R|/single|()
|
||||
^test this@R|/LightClassWrapper|.R|/Light.typeParameters|.R|/single|()
|
||||
}
|
||||
|
||||
}
|
||||
@@ -47,7 +47,7 @@ FILE: Test.kt
|
||||
public final fun test(other: R|kotlin/Any?|): R|kotlin/Unit| {
|
||||
when () {
|
||||
(R|<local>/other| is R|LightField<*>|) -> {
|
||||
R|<local>/other|.R|/LightField.name|
|
||||
R|<local>/other|.R|/LightMember.name|
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+18
@@ -2999,6 +2999,18 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/definitelyNotNullAndOriginalType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("doubleGenericDiamond.kt")
|
||||
public void testDoubleGenericDiamond() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/doubleGenericDiamond.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("falseIntersection.kt")
|
||||
public void testFalseIntersection() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/falseIntersection.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("flexibleTypeVarAgainstNull.kt")
|
||||
public void testFlexibleTypeVarAgainstNull() throws Exception {
|
||||
@@ -3064,6 +3076,12 @@ public class FirDiagnosticTestGenerated extends AbstractFirDiagnosticTest {
|
||||
public void testSecondaryConstructorCfg() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/secondaryConstructorCfg.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("transform.kt")
|
||||
public void testTransform() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/transform.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+18
@@ -3033,6 +3033,18 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/definitelyNotNullAndOriginalType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("doubleGenericDiamond.kt")
|
||||
public void testDoubleGenericDiamond() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/doubleGenericDiamond.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("falseIntersection.kt")
|
||||
public void testFalseIntersection() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/falseIntersection.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("flexibleTypeVarAgainstNull.kt")
|
||||
public void testFlexibleTypeVarAgainstNull() throws Exception {
|
||||
@@ -3098,6 +3110,12 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
|
||||
public void testSecondaryConstructorCfg() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/secondaryConstructorCfg.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("transform.kt")
|
||||
public void testTransform() throws Exception {
|
||||
runTest("compiler/fir/analysis-tests/testData/resolve/problems/transform.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+57
-10
@@ -8,15 +8,12 @@ package org.jetbrains.kotlin.fir.scopes.impl
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.*
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.dispatchReceiverClassOrNull
|
||||
import org.jetbrains.kotlin.fir.originalForIntersectionOverrideAttr
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
|
||||
import org.jetbrains.kotlin.fir.scopes.*
|
||||
import org.jetbrains.kotlin.name.CallableId
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.fir.typeContext
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
@@ -94,15 +91,15 @@ class FirTypeIntersectionScope private constructor(
|
||||
members.map { MemberWithBaseScope(it, scope) }
|
||||
}
|
||||
|
||||
while (allMembersWithScope.isNotEmpty()) {
|
||||
while (allMembersWithScope.size > 1) {
|
||||
val maxByVisibility = findMemberWithMaxVisibility(allMembersWithScope)
|
||||
val extractBothWaysWithPrivate = extractBothWaysOverridable(maxByVisibility, allMembersWithScope)
|
||||
val extractedOverrides = extractBothWaysWithPrivate.filterNot {
|
||||
val extractedOverrides = extractBothWaysWithPrivate.filterNotTo(mutableListOf()) {
|
||||
Visibilities.isPrivate((it.member.fir as FirMemberDeclaration).visibility)
|
||||
}.takeIf { it.isNotEmpty() } ?: extractBothWaysWithPrivate
|
||||
|
||||
val (mostSpecific, scopeForMostSpecific) = selectMostSpecificMember(extractedOverrides)
|
||||
if (extractedOverrides.size > 1) {
|
||||
val baseMembersForIntersection = extractedOverrides.calcBaseMembersForIntersectionOverride()
|
||||
if (baseMembersForIntersection.size > 1) {
|
||||
val (mostSpecific, scopeForMostSpecific) = selectMostSpecificMember(baseMembersForIntersection)
|
||||
val intersectionOverride = intersectionOverrides.getOrPut(mostSpecific) {
|
||||
val newModality = chooseIntersectionOverrideModality(extractedOverrides)
|
||||
val newVisibility = chooseIntersectionVisibility(extractedOverrides)
|
||||
@@ -124,14 +121,64 @@ class FirTypeIntersectionScope private constructor(
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
processor(intersectionOverride.member as D)
|
||||
} else {
|
||||
val mostSpecific = baseMembersForIntersection.single().member
|
||||
overriddenSymbols[mostSpecific] = extractedOverrides
|
||||
processor(mostSpecific)
|
||||
}
|
||||
}
|
||||
|
||||
if (allMembersWithScope.isNotEmpty()) {
|
||||
val single = allMembersWithScope.single().member
|
||||
overriddenSymbols[single] = allMembersWithScope.toList()
|
||||
processor(single)
|
||||
}
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
private inline fun <reified D : FirCallableDeclaration<*>> D.unwrapSubstitutionOverrides(): D {
|
||||
var current = this
|
||||
|
||||
do {
|
||||
val next = current.originalForSubstitutionOverride ?: return current
|
||||
current = next
|
||||
} while (true)
|
||||
}
|
||||
|
||||
private fun <S : FirCallableSymbol<*>>
|
||||
MutableList<MemberWithBaseScope<S>>.calcBaseMembersForIntersectionOverride(): List<MemberWithBaseScope<S>> {
|
||||
if (size == 1) return this
|
||||
val unwrappedMemberSet = mutableSetOf<MemberWithBaseScope<S>>()
|
||||
for ((member, scope) in this) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
unwrappedMemberSet += MemberWithBaseScope(member.fir.unwrapSubstitutionOverrides().symbol as S, scope)
|
||||
}
|
||||
// If in fact extracted overrides are the same symbols,
|
||||
// we should just take most specific member without creating intersection
|
||||
// A typical sample here is inheritance of the same class in different places of hierarchy
|
||||
if (unwrappedMemberSet.size == 1) {
|
||||
return listOf(selectMostSpecificMember(this))
|
||||
}
|
||||
|
||||
val baseMembers = mutableSetOf<S>()
|
||||
for ((unwrappedMember, scope) in unwrappedMemberSet) {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
if (unwrappedMember is FirNamedFunctionSymbol) {
|
||||
scope.processOverriddenFunctions(unwrappedMember) {
|
||||
baseMembers += it.fir.unwrapSubstitutionOverrides().symbol as S
|
||||
ProcessorAction.NEXT
|
||||
}
|
||||
} else if (unwrappedMember is FirPropertySymbol) {
|
||||
scope.processOverriddenProperties(unwrappedMember) {
|
||||
baseMembers += it.fir.unwrapSubstitutionOverrides().symbol as S
|
||||
ProcessorAction.NEXT
|
||||
}
|
||||
}
|
||||
}
|
||||
removeIf { (member, _) -> member.fir.unwrapSubstitutionOverrides().symbol in baseMembers }
|
||||
return this
|
||||
}
|
||||
|
||||
private fun <D : FirCallableSymbol<*>> chooseIntersectionOverrideModality(
|
||||
extractedOverridden: Collection<MemberWithBaseScope<D>>
|
||||
): Modality? {
|
||||
@@ -397,7 +444,7 @@ class FirTypeIntersectionScope private constructor(
|
||||
private fun <D : FirCallableSymbol<*>> extractBothWaysOverridable(
|
||||
overrider: MemberWithBaseScope<D>,
|
||||
members: MutableCollection<MemberWithBaseScope<D>>
|
||||
): Collection<MemberWithBaseScope<D>> {
|
||||
): MutableList<MemberWithBaseScope<D>> {
|
||||
val result = mutableListOf<MemberWithBaseScope<D>>().apply { add(overrider) }
|
||||
|
||||
val iterator = members.iterator()
|
||||
|
||||
Reference in New Issue
Block a user