FIR: Fix scope intersection types

Otherwise overload resolution ambiguity is reported in the test
This commit is contained in:
Denis Zharkov
2020-01-29 17:35:47 +03:00
parent d28e1f156a
commit 47ecaa5b06
24 changed files with 114 additions and 61 deletions
@@ -12,7 +12,10 @@ import org.jetbrains.kotlin.fir.declarations.FirRegularClass
import org.jetbrains.kotlin.fir.declarations.FirTypeParametersOwner
import org.jetbrains.kotlin.fir.resolve.substitution.substitutorByMap
import org.jetbrains.kotlin.fir.scopes.FirScope
import org.jetbrains.kotlin.fir.scopes.impl.*
import org.jetbrains.kotlin.fir.scopes.impl.FirCompositeScope
import org.jetbrains.kotlin.fir.scopes.impl.FirIntegerLiteralTypeScope
import org.jetbrains.kotlin.fir.scopes.impl.FirStandardOverrideChecker
import org.jetbrains.kotlin.fir.scopes.impl.FirSuperTypeScope
import org.jetbrains.kotlin.fir.scopes.scope
import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
@@ -43,7 +46,9 @@ fun ConeKotlinType.scope(useSiteSession: FirSession, scopeSession: ScopeSession)
}
is ConeRawType -> lowerBound.scope(useSiteSession, scopeSession)
is ConeFlexibleType -> lowerBound.scope(useSiteSession, scopeSession)
is ConeIntersectionType -> FirCompositeScope(
is ConeIntersectionType -> FirSuperTypeScope.prepareSupertypeScope(
useSiteSession,
FirStandardOverrideChecker(useSiteSession),
intersectedTypes.mapNotNullTo(mutableListOf()) {
it.scope(useSiteSession, scopeSession)
}
@@ -0,0 +1,14 @@
interface A {
fun foo()
}
abstract class B : A {
override fun foo() {}
}
interface C : A {}
fun main(c: C) {
if (c !is B) return
c.foo()
}
@@ -0,0 +1,25 @@
FILE: intersectionScope.kt
public abstract interface A : R|kotlin/Any| {
public abstract fun foo(): R|kotlin/Unit|
}
public abstract class B : R|A| {
public constructor(): R|B| {
super<R|kotlin/Any|>()
}
public open override fun foo(): R|kotlin/Unit| {
}
}
public abstract interface C : R|A| {
}
public final fun main(c: R|C|): R|kotlin/Unit| {
when () {
(R|<local>/c| !is R|B|) -> {
^main Unit
}
}
R|<local>/c|.R|/B.foo|()
}
@@ -143,6 +143,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest {
runTest("compiler/fir/resolve/testData/resolve/genericFunctions.kt");
}
@TestMetadata("intersectionScope.kt")
public void testIntersectionScope() throws Exception {
runTest("compiler/fir/resolve/testData/resolve/intersectionScope.kt");
}
@TestMetadata("intersectionTypes.kt")
public void testIntersectionTypes() throws Exception {
runTest("compiler/fir/resolve/testData/resolve/intersectionTypes.kt");
@@ -143,6 +143,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos
runTest("compiler/fir/resolve/testData/resolve/genericFunctions.kt");
}
@TestMetadata("intersectionScope.kt")
public void testIntersectionScope() throws Exception {
runTest("compiler/fir/resolve/testData/resolve/intersectionScope.kt");
}
@TestMetadata("intersectionTypes.kt")
public void testIntersectionTypes() throws Exception {
runTest("compiler/fir/resolve/testData/resolve/intersectionTypes.kt");