FIR IDE: add API to get super types of a KtType
This commit is contained in:
committed by
Ilya Kirillov
parent
09d16ce849
commit
8b44a4685f
+77
@@ -20,12 +20,24 @@ import org.jetbrains.kotlin.analysis.api.withValidityAssertion
|
|||||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.LowLevelFirApiFacadeForResolveOnAir.getTowerContextProvider
|
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.LowLevelFirApiFacadeForResolveOnAir.getTowerContextProvider
|
||||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.getOrBuildFir
|
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.getOrBuildFir
|
||||||
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.throwUnexpectedFirElementError
|
import org.jetbrains.kotlin.analysis.low.level.api.fir.api.throwUnexpectedFirElementError
|
||||||
|
import org.jetbrains.kotlin.fir.FirRenderer
|
||||||
import org.jetbrains.kotlin.fir.analysis.checkers.ConeTypeCompatibilityChecker
|
import org.jetbrains.kotlin.fir.analysis.checkers.ConeTypeCompatibilityChecker
|
||||||
import org.jetbrains.kotlin.fir.analysis.checkers.ConeTypeCompatibilityChecker.isCompatible
|
import org.jetbrains.kotlin.fir.analysis.checkers.ConeTypeCompatibilityChecker.isCompatible
|
||||||
|
import org.jetbrains.kotlin.fir.analysis.checkers.fullyExpandedClass
|
||||||
|
import org.jetbrains.kotlin.fir.analysis.checkers.typeParameterSymbols
|
||||||
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
|
||||||
|
import org.jetbrains.kotlin.fir.declarations.utils.superConeTypes
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirCallableReferenceAccess
|
import org.jetbrains.kotlin.fir.expressions.FirCallableReferenceAccess
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall
|
import org.jetbrains.kotlin.fir.expressions.FirDelegatedConstructorCall
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirGetClassCall
|
import org.jetbrains.kotlin.fir.expressions.FirGetClassCall
|
||||||
|
import org.jetbrains.kotlin.fir.render
|
||||||
|
import org.jetbrains.kotlin.fir.resolve.inference.inferenceComponents
|
||||||
|
import org.jetbrains.kotlin.fir.resolve.substitution.substitutorByMap
|
||||||
|
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.impl.FirAnonymousObjectSymbol
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeAliasSymbol
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
|
||||||
import org.jetbrains.kotlin.fir.typeContext
|
import org.jetbrains.kotlin.fir.typeContext
|
||||||
import org.jetbrains.kotlin.fir.types.*
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
|
import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
|
||||||
@@ -34,6 +46,8 @@ import org.jetbrains.kotlin.name.StandardClassIds
|
|||||||
import org.jetbrains.kotlin.psi.KtDoubleColonExpression
|
import org.jetbrains.kotlin.psi.KtDoubleColonExpression
|
||||||
import org.jetbrains.kotlin.psi.KtElement
|
import org.jetbrains.kotlin.psi.KtElement
|
||||||
import org.jetbrains.kotlin.psi.KtTypeReference
|
import org.jetbrains.kotlin.psi.KtTypeReference
|
||||||
|
import org.jetbrains.kotlin.types.TypeApproximatorConfiguration
|
||||||
|
import org.jetbrains.kotlin.types.model.CaptureStatus
|
||||||
|
|
||||||
internal class KtFirTypeProvider(
|
internal class KtFirTypeProvider(
|
||||||
override val analysisSession: KtFirAnalysisSession,
|
override val analysisSession: KtFirAnalysisSession,
|
||||||
@@ -110,5 +124,68 @@ internal class KtFirTypeProvider(
|
|||||||
return analysisSession.firResolveState.getTowerContextProvider()
|
return analysisSession.firResolveState.getTowerContextProvider()
|
||||||
.getClosestAvailableParentContext(position)?.implicitReceiverStack?.map { it.type.asKtType() } ?: emptyList()
|
.getClosestAvailableParentContext(position)?.implicitReceiverStack?.map { it.type.asKtType() } ?: emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getDirectSuperTypes(type: KtType, shouldApproximate: Boolean): List<KtType> {
|
||||||
|
require(type is KtFirType)
|
||||||
|
return type.coneType.getDirectSuperTypes(shouldApproximate).mapTo(mutableListOf()) { it.asKtType() }
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun ConeKotlinType.getDirectSuperTypes(shouldApproximate: Boolean): Sequence<ConeKotlinType> {
|
||||||
|
return when (this) {
|
||||||
|
// We also need to collect those on `upperBound` due to nullability.
|
||||||
|
is ConeFlexibleType -> lowerBound.getDirectSuperTypes(shouldApproximate) + upperBound.getDirectSuperTypes(shouldApproximate)
|
||||||
|
is ConeDefinitelyNotNullType -> original.getDirectSuperTypes(shouldApproximate).map { ConeDefinitelyNotNullType(it) }
|
||||||
|
is ConeIntersectionType -> intersectedTypes.asSequence().flatMap { it.getDirectSuperTypes(shouldApproximate) }
|
||||||
|
is ConeClassErrorType -> emptySequence()
|
||||||
|
is ConeLookupTagBasedType -> getSubstitutedSuperTypes(shouldApproximate)
|
||||||
|
else -> emptySequence()
|
||||||
|
}.distinct()
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun ConeLookupTagBasedType.getSubstitutedSuperTypes(shouldApproximate: Boolean): Sequence<ConeKotlinType> {
|
||||||
|
val session = analysisSession.firResolveState.rootModuleSession
|
||||||
|
val symbol = lookupTag.toSymbol(session)
|
||||||
|
val superTypes = when (symbol) {
|
||||||
|
is FirAnonymousObjectSymbol -> symbol.superConeTypes
|
||||||
|
is FirRegularClassSymbol -> symbol.superConeTypes
|
||||||
|
is FirTypeAliasSymbol -> symbol.fullyExpandedClass(session)?.superConeTypes ?: return emptySequence()
|
||||||
|
is FirTypeParameterSymbol -> symbol.resolvedBounds.map { it.type }
|
||||||
|
else -> return emptySequence()
|
||||||
|
}
|
||||||
|
|
||||||
|
val typeParameterSymbols = symbol.typeParameterSymbols ?: return superTypes.asSequence()
|
||||||
|
val argumentTypes = (session.typeContext.captureArguments(this, CaptureStatus.FROM_EXPRESSION)?.toList()
|
||||||
|
?: this.typeArguments.mapNotNull { it.type })
|
||||||
|
|
||||||
|
require(typeParameterSymbols.size == argumentTypes.size) {
|
||||||
|
"'${symbol.fir.render(FirRenderer.RenderMode.NoBodies)}' expects '${typeParameterSymbols.size}' type arguments " +
|
||||||
|
"but type '${this.render()}' has ${argumentTypes.size} type arguments."
|
||||||
|
}
|
||||||
|
|
||||||
|
val substitutor = substitutorByMap(typeParameterSymbols.zip(argumentTypes).toMap(), session)
|
||||||
|
return superTypes.asSequence().map {
|
||||||
|
val type = substitutor.substituteOrSelf(it)
|
||||||
|
if (shouldApproximate) {
|
||||||
|
session.inferenceComponents.approximator.approximateToSuperType(
|
||||||
|
type,
|
||||||
|
TypeApproximatorConfiguration.FinalApproximationAfterResolutionAndInference
|
||||||
|
) ?: type
|
||||||
|
} else {
|
||||||
|
type
|
||||||
|
}.withNullability(nullability, session.typeContext)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getAllSuperTypes(type: KtType, shouldApproximate: Boolean): List<KtType> {
|
||||||
|
require(type is KtFirType)
|
||||||
|
val queue = type.coneType.getDirectSuperTypes(shouldApproximate).toCollection(ArrayDeque())
|
||||||
|
return buildSet {
|
||||||
|
while (queue.isNotEmpty()) {
|
||||||
|
val current = queue.removeFirst()
|
||||||
|
if (!add(current)) continue
|
||||||
|
queue.addAll(current.getDirectSuperTypes(shouldApproximate))
|
||||||
|
}
|
||||||
|
}.map { it.asKtType() }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+47
@@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.analysis.api.fir.components
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.analysis.api.analyse
|
||||||
|
import org.jetbrains.kotlin.analysis.api.fir.executeOnPooledThreadInReadAction
|
||||||
|
import org.jetbrains.kotlin.analysis.api.fir.test.framework.AbstractHLApiSingleFileTest
|
||||||
|
import org.jetbrains.kotlin.analysis.api.types.KtType
|
||||||
|
import org.jetbrains.kotlin.analysis.low.level.api.fir.test.base.expressionMarkerProvider
|
||||||
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
|
import org.jetbrains.kotlin.test.model.TestModule
|
||||||
|
import org.jetbrains.kotlin.test.services.TestServices
|
||||||
|
import org.jetbrains.kotlin.test.services.assertions
|
||||||
|
|
||||||
|
abstract class AbstractGetSuperTypesTest : AbstractHLApiSingleFileTest() {
|
||||||
|
override fun doTestByFileStructure(ktFile: KtFile, module: TestModule, testServices: TestServices) {
|
||||||
|
val expression = testServices.expressionMarkerProvider.getSelectedElement(ktFile)
|
||||||
|
|
||||||
|
val actual = executeOnPooledThreadInReadAction {
|
||||||
|
analyse(expression) {
|
||||||
|
val expectedType = expression.getExpectedType() ?: error("expect to get type of expression '${expression.text}'")
|
||||||
|
val directSuperTypes = expectedType.getDirectSuperTypes()
|
||||||
|
val approximatedDirectSuperTypes = expectedType.getDirectSuperTypes(shouldApproximate = true)
|
||||||
|
val allSuperTypes = expectedType.getAllSuperTypes()
|
||||||
|
val approximatedAllSuperTypes = expectedType.getAllSuperTypes(shouldApproximate = true)
|
||||||
|
|
||||||
|
buildString {
|
||||||
|
fun List<KtType>.print(name: String) {
|
||||||
|
appendLine(name)
|
||||||
|
for (type in this) {
|
||||||
|
appendLine(type.render())
|
||||||
|
}
|
||||||
|
appendLine()
|
||||||
|
}
|
||||||
|
directSuperTypes.print("[direct super types]")
|
||||||
|
approximatedDirectSuperTypes.print("[approximated direct super types]")
|
||||||
|
allSuperTypes.print("[all super types]")
|
||||||
|
approximatedAllSuperTypes.print("[approximated all super types]")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
testServices.assertions.assertEqualsToFile(testDataFileSibling(".txt"), actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
+110
@@ -0,0 +1,110 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.analysis.api.fir.components;
|
||||||
|
|
||||||
|
import com.intellij.testFramework.TestDataPath;
|
||||||
|
import org.jetbrains.kotlin.test.util.KtTestUtil;
|
||||||
|
import org.jetbrains.kotlin.test.TestMetadata;
|
||||||
|
import org.junit.jupiter.api.Nested;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
/** This class is generated by {@link GenerateNewCompilerTests.kt}. DO NOT MODIFY MANUALLY */
|
||||||
|
@SuppressWarnings("all")
|
||||||
|
@TestMetadata("analysis/analysis-api/testData/components/getSuperTypes")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
public class GetSuperTypesTestGenerated extends AbstractGetSuperTypesTest {
|
||||||
|
@Test
|
||||||
|
public void testAllFilesPresentInGetSuperTypes() throws Exception {
|
||||||
|
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/getSuperTypes"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("anonymousObject.kt")
|
||||||
|
public void testAnonymousObject() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/getSuperTypes/anonymousObject.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("any.kt")
|
||||||
|
public void testAny() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/getSuperTypes/any.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("contravariant.kt")
|
||||||
|
public void testContravariant() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/getSuperTypes/contravariant.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("covariant.kt")
|
||||||
|
public void testCovariant() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/getSuperTypes/covariant.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("errorType.kt")
|
||||||
|
public void testErrorType() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/getSuperTypes/errorType.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("flexibleType.kt")
|
||||||
|
public void testFlexibleType() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/getSuperTypes/flexibleType.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("int.kt")
|
||||||
|
public void testInt() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/getSuperTypes/int.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("invariant.kt")
|
||||||
|
public void testInvariant() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/getSuperTypes/invariant.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("recursiveTypeParameter.kt")
|
||||||
|
public void testRecursiveTypeParameter() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/getSuperTypes/recursiveTypeParameter.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("regularClass.kt")
|
||||||
|
public void testRegularClass() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/getSuperTypes/regularClass.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("regularClassWithBounds.kt")
|
||||||
|
public void testRegularClassWithBounds() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/getSuperTypes/regularClassWithBounds.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("star.kt")
|
||||||
|
public void testStar() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/getSuperTypes/star.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("string.kt")
|
||||||
|
public void testString() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/getSuperTypes/string.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@TestMetadata("typeParameter.kt")
|
||||||
|
public void testTypeParameter() throws Exception {
|
||||||
|
runTest("analysis/analysis-api/testData/components/getSuperTypes/typeParameter.kt");
|
||||||
|
}
|
||||||
|
}
|
||||||
+27
@@ -32,6 +32,11 @@ public abstract class KtTypeProvider : KtAnalysisSessionComponent() {
|
|||||||
public abstract fun haveCommonSubtype(a: KtType, b: KtType): Boolean
|
public abstract fun haveCommonSubtype(a: KtType, b: KtType): Boolean
|
||||||
|
|
||||||
public abstract fun getImplicitReceiverTypesAtPosition(position: KtElement): List<KtType>
|
public abstract fun getImplicitReceiverTypesAtPosition(position: KtElement): List<KtType>
|
||||||
|
|
||||||
|
public abstract fun getDirectSuperTypes(type: KtType, shouldApproximate: Boolean): List<KtType>
|
||||||
|
|
||||||
|
public abstract fun getAllSuperTypes(type: KtType, shouldApproximate: Boolean): List<KtType>
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface KtTypeProviderMixIn : KtAnalysisSessionMixIn {
|
public interface KtTypeProviderMixIn : KtAnalysisSessionMixIn {
|
||||||
@@ -91,6 +96,28 @@ public interface KtTypeProviderMixIn : KtAnalysisSessionMixIn {
|
|||||||
*/
|
*/
|
||||||
public fun getImplicitReceiverTypesAtPosition(position: KtElement): List<KtType> =
|
public fun getImplicitReceiverTypesAtPosition(position: KtElement): List<KtType> =
|
||||||
analysisSession.typeProvider.getImplicitReceiverTypesAtPosition(position)
|
analysisSession.typeProvider.getImplicitReceiverTypesAtPosition(position)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the direct super types of the given type. For example, given `MutableList<String>`, this returns `List<String>` and
|
||||||
|
* `MutableCollection<String>`.
|
||||||
|
*
|
||||||
|
* Note that for flexible types, both direct super types of the upper and lower bounds are returned. If that's not desirable, please
|
||||||
|
* first call [KtFlexibleType.upperBound] or [KtFlexibleType.lowerBound] and then call this method.
|
||||||
|
*
|
||||||
|
* @param shouldApproximate whether to approximate non-denotable types. For example, super type of `List<out String>` is
|
||||||
|
* `Collection<CAPTURED out String>`. With approximation set to true, `Collection<out String>` is returned instead.
|
||||||
|
*/
|
||||||
|
public fun KtType.getDirectSuperTypes(shouldApproximate: Boolean = false): List<KtType> =
|
||||||
|
analysisSession.typeProvider.getDirectSuperTypes(this, shouldApproximate)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets all the super types of the given type. The returned result is ordered by a BFS traversal of the class hierarchy, without any
|
||||||
|
* duplicates.
|
||||||
|
*
|
||||||
|
* @param shouldApproximate see [getDirectSuperTypes]
|
||||||
|
*/
|
||||||
|
public fun KtType.getAllSuperTypes(shouldApproximate: Boolean = false): List<KtType> =
|
||||||
|
analysisSession.typeProvider.getAllSuperTypes(this, shouldApproximate)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("PropertyName")
|
@Suppress("PropertyName")
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
interface A
|
||||||
|
interface B
|
||||||
|
val o = object: A, B {}
|
||||||
|
val o2 = <expr>o</expr>
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
[direct super types]
|
||||||
|
A
|
||||||
|
B
|
||||||
|
|
||||||
|
[approximated direct super types]
|
||||||
|
A
|
||||||
|
B
|
||||||
|
|
||||||
|
[all super types]
|
||||||
|
A
|
||||||
|
B
|
||||||
|
kotlin.Any
|
||||||
|
|
||||||
|
[approximated all super types]
|
||||||
|
A
|
||||||
|
B
|
||||||
|
kotlin.Any
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
val a = <expr>Any()</expr>
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
[direct super types]
|
||||||
|
|
||||||
|
[approximated direct super types]
|
||||||
|
|
||||||
|
[all super types]
|
||||||
|
|
||||||
|
[approximated all super types]
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
val s = <expr>get()</expr>
|
||||||
|
|
||||||
|
fun get() : MutableList<in String>
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
[direct super types]
|
||||||
|
kotlin.collections.List<ERROR_TYPE <Unexpected cone type org.jetbrains.kotlin.fir.types.ConeCapturedType>>
|
||||||
|
kotlin.collections.MutableCollection<ERROR_TYPE <Unexpected cone type org.jetbrains.kotlin.fir.types.ConeCapturedType>>
|
||||||
|
|
||||||
|
[approximated direct super types]
|
||||||
|
kotlin.collections.List<kotlin.Any?>
|
||||||
|
kotlin.collections.MutableCollection<in kotlin.String>
|
||||||
|
|
||||||
|
[all super types]
|
||||||
|
kotlin.collections.List<ERROR_TYPE <Unexpected cone type org.jetbrains.kotlin.fir.types.ConeCapturedType>>
|
||||||
|
kotlin.collections.MutableCollection<ERROR_TYPE <Unexpected cone type org.jetbrains.kotlin.fir.types.ConeCapturedType>>
|
||||||
|
kotlin.collections.Collection<ERROR_TYPE <Unexpected cone type org.jetbrains.kotlin.fir.types.ConeCapturedType>>
|
||||||
|
kotlin.collections.MutableIterable<ERROR_TYPE <Unexpected cone type org.jetbrains.kotlin.fir.types.ConeCapturedType>>
|
||||||
|
kotlin.collections.Iterable<ERROR_TYPE <Unexpected cone type org.jetbrains.kotlin.fir.types.ConeCapturedType>>
|
||||||
|
kotlin.Any
|
||||||
|
|
||||||
|
[approximated all super types]
|
||||||
|
kotlin.collections.List<kotlin.Any?>
|
||||||
|
kotlin.collections.MutableCollection<in kotlin.String>
|
||||||
|
kotlin.collections.Collection<kotlin.Any?>
|
||||||
|
kotlin.collections.MutableIterable<kotlin.Any?>
|
||||||
|
kotlin.collections.Iterable<kotlin.Any?>
|
||||||
|
kotlin.Any
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
val s = <expr>get()</expr>
|
||||||
|
|
||||||
|
fun get() : MutableList<out String>
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
[direct super types]
|
||||||
|
kotlin.collections.List<ERROR_TYPE <Unexpected cone type org.jetbrains.kotlin.fir.types.ConeCapturedType>>
|
||||||
|
kotlin.collections.MutableCollection<ERROR_TYPE <Unexpected cone type org.jetbrains.kotlin.fir.types.ConeCapturedType>>
|
||||||
|
|
||||||
|
[approximated direct super types]
|
||||||
|
kotlin.collections.List<kotlin.String>
|
||||||
|
kotlin.collections.MutableCollection<out kotlin.String>
|
||||||
|
|
||||||
|
[all super types]
|
||||||
|
kotlin.collections.List<ERROR_TYPE <Unexpected cone type org.jetbrains.kotlin.fir.types.ConeCapturedType>>
|
||||||
|
kotlin.collections.MutableCollection<ERROR_TYPE <Unexpected cone type org.jetbrains.kotlin.fir.types.ConeCapturedType>>
|
||||||
|
kotlin.collections.Collection<ERROR_TYPE <Unexpected cone type org.jetbrains.kotlin.fir.types.ConeCapturedType>>
|
||||||
|
kotlin.collections.MutableIterable<ERROR_TYPE <Unexpected cone type org.jetbrains.kotlin.fir.types.ConeCapturedType>>
|
||||||
|
kotlin.collections.Iterable<ERROR_TYPE <Unexpected cone type org.jetbrains.kotlin.fir.types.ConeCapturedType>>
|
||||||
|
kotlin.Any
|
||||||
|
|
||||||
|
[approximated all super types]
|
||||||
|
kotlin.collections.List<kotlin.String>
|
||||||
|
kotlin.collections.MutableCollection<out kotlin.String>
|
||||||
|
kotlin.collections.Collection<kotlin.String>
|
||||||
|
kotlin.collections.MutableIterable<kotlin.String>
|
||||||
|
kotlin.collections.Iterable<kotlin.String>
|
||||||
|
kotlin.Any
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
val i: UnresolvedType? = null
|
||||||
|
val j = <expr>i</expr>
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
[direct super types]
|
||||||
|
|
||||||
|
[approximated direct super types]
|
||||||
|
|
||||||
|
[all super types]
|
||||||
|
|
||||||
|
[approximated all super types]
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
// FILE: Java.java
|
||||||
|
import java.util.List
|
||||||
|
|
||||||
|
class Java {
|
||||||
|
public static List<String> getNames() {
|
||||||
|
throw Exception()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// FILE: test.kt
|
||||||
|
|
||||||
|
val i = <expr>Java.getNames()</expr>
|
||||||
@@ -0,0 +1,32 @@
|
|||||||
|
[direct super types]
|
||||||
|
kotlin.collections.List<kotlin.String!>
|
||||||
|
kotlin.collections.MutableCollection<kotlin.String!>
|
||||||
|
kotlin.collections.Collection<kotlin.String!>?
|
||||||
|
|
||||||
|
[approximated direct super types]
|
||||||
|
kotlin.collections.List<kotlin.String!>
|
||||||
|
kotlin.collections.MutableCollection<kotlin.String!>
|
||||||
|
kotlin.collections.Collection<kotlin.String!>?
|
||||||
|
|
||||||
|
[all super types]
|
||||||
|
kotlin.collections.List<kotlin.String!>
|
||||||
|
kotlin.collections.MutableCollection<kotlin.String!>
|
||||||
|
kotlin.collections.Collection<kotlin.String!>?
|
||||||
|
kotlin.collections.Collection<kotlin.String!>
|
||||||
|
kotlin.collections.MutableIterable<kotlin.String!>
|
||||||
|
kotlin.collections.Iterable<kotlin.String!>?
|
||||||
|
kotlin.collections.Iterable<kotlin.String!>
|
||||||
|
kotlin.Any?
|
||||||
|
kotlin.Any
|
||||||
|
|
||||||
|
[approximated all super types]
|
||||||
|
kotlin.collections.List<kotlin.String!>
|
||||||
|
kotlin.collections.MutableCollection<kotlin.String!>
|
||||||
|
kotlin.collections.Collection<kotlin.String!>?
|
||||||
|
kotlin.collections.Collection<kotlin.String!>
|
||||||
|
kotlin.collections.MutableIterable<kotlin.String!>
|
||||||
|
kotlin.collections.Iterable<kotlin.String!>?
|
||||||
|
kotlin.collections.Iterable<kotlin.String!>
|
||||||
|
kotlin.Any?
|
||||||
|
kotlin.Any
|
||||||
|
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
val i = <expr>1</expr>
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
[direct super types]
|
||||||
|
kotlin.Number
|
||||||
|
kotlin.Comparable<kotlin.Int>
|
||||||
|
java.io.Serializable
|
||||||
|
|
||||||
|
[approximated direct super types]
|
||||||
|
kotlin.Number
|
||||||
|
kotlin.Comparable<kotlin.Int>
|
||||||
|
java.io.Serializable
|
||||||
|
|
||||||
|
[all super types]
|
||||||
|
kotlin.Number
|
||||||
|
kotlin.Comparable<kotlin.Int>
|
||||||
|
java.io.Serializable
|
||||||
|
kotlin.Any
|
||||||
|
|
||||||
|
[approximated all super types]
|
||||||
|
kotlin.Number
|
||||||
|
kotlin.Comparable<kotlin.Int>
|
||||||
|
java.io.Serializable
|
||||||
|
kotlin.Any
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
val s = <expr>get()</expr>
|
||||||
|
|
||||||
|
fun get() : MutableList<String>
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
[direct super types]
|
||||||
|
kotlin.collections.List<kotlin.String>
|
||||||
|
kotlin.collections.MutableCollection<kotlin.String>
|
||||||
|
|
||||||
|
[approximated direct super types]
|
||||||
|
kotlin.collections.List<kotlin.String>
|
||||||
|
kotlin.collections.MutableCollection<kotlin.String>
|
||||||
|
|
||||||
|
[all super types]
|
||||||
|
kotlin.collections.List<kotlin.String>
|
||||||
|
kotlin.collections.MutableCollection<kotlin.String>
|
||||||
|
kotlin.collections.Collection<kotlin.String>
|
||||||
|
kotlin.collections.MutableIterable<kotlin.String>
|
||||||
|
kotlin.collections.Iterable<kotlin.String>
|
||||||
|
kotlin.Any
|
||||||
|
|
||||||
|
[approximated all super types]
|
||||||
|
kotlin.collections.List<kotlin.String>
|
||||||
|
kotlin.collections.MutableCollection<kotlin.String>
|
||||||
|
kotlin.collections.Collection<kotlin.String>
|
||||||
|
kotlin.collections.MutableIterable<kotlin.String>
|
||||||
|
kotlin.collections.Iterable<kotlin.String>
|
||||||
|
kotlin.Any
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
class Foo<T : Foo<T>>(t: T) {
|
||||||
|
val t2 = <expr>t</expr>
|
||||||
|
}
|
||||||
+13
@@ -0,0 +1,13 @@
|
|||||||
|
[direct super types]
|
||||||
|
Foo<T>
|
||||||
|
|
||||||
|
[approximated direct super types]
|
||||||
|
Foo<T>
|
||||||
|
|
||||||
|
[all super types]
|
||||||
|
Foo<T>
|
||||||
|
kotlin.Any
|
||||||
|
|
||||||
|
[approximated all super types]
|
||||||
|
Foo<T>
|
||||||
|
kotlin.Any
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
class A
|
||||||
|
|
||||||
|
val a = <expr>A()</expr>
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
[direct super types]
|
||||||
|
kotlin.Any
|
||||||
|
|
||||||
|
[approximated direct super types]
|
||||||
|
kotlin.Any
|
||||||
|
|
||||||
|
[all super types]
|
||||||
|
kotlin.Any
|
||||||
|
|
||||||
|
[approximated all super types]
|
||||||
|
kotlin.Any
|
||||||
+5
@@ -0,0 +1,5 @@
|
|||||||
|
interface I
|
||||||
|
open class A
|
||||||
|
class B: A(), I
|
||||||
|
|
||||||
|
val b = <expr>B()</expr>
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
[direct super types]
|
||||||
|
A
|
||||||
|
I
|
||||||
|
|
||||||
|
[approximated direct super types]
|
||||||
|
A
|
||||||
|
I
|
||||||
|
|
||||||
|
[all super types]
|
||||||
|
A
|
||||||
|
I
|
||||||
|
kotlin.Any
|
||||||
|
|
||||||
|
[approximated all super types]
|
||||||
|
A
|
||||||
|
I
|
||||||
|
kotlin.Any
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
val s = <expr>get()</expr>
|
||||||
|
|
||||||
|
fun get() : MutableList<*>
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
[direct super types]
|
||||||
|
kotlin.collections.List<ERROR_TYPE <Unexpected cone type org.jetbrains.kotlin.fir.types.ConeCapturedType>>
|
||||||
|
kotlin.collections.MutableCollection<ERROR_TYPE <Unexpected cone type org.jetbrains.kotlin.fir.types.ConeCapturedType>>
|
||||||
|
|
||||||
|
[approximated direct super types]
|
||||||
|
kotlin.collections.List<kotlin.Any?>
|
||||||
|
kotlin.collections.MutableCollection<out kotlin.Any?>
|
||||||
|
|
||||||
|
[all super types]
|
||||||
|
kotlin.collections.List<ERROR_TYPE <Unexpected cone type org.jetbrains.kotlin.fir.types.ConeCapturedType>>
|
||||||
|
kotlin.collections.MutableCollection<ERROR_TYPE <Unexpected cone type org.jetbrains.kotlin.fir.types.ConeCapturedType>>
|
||||||
|
kotlin.collections.Collection<ERROR_TYPE <Unexpected cone type org.jetbrains.kotlin.fir.types.ConeCapturedType>>
|
||||||
|
kotlin.collections.MutableIterable<ERROR_TYPE <Unexpected cone type org.jetbrains.kotlin.fir.types.ConeCapturedType>>
|
||||||
|
kotlin.collections.Iterable<ERROR_TYPE <Unexpected cone type org.jetbrains.kotlin.fir.types.ConeCapturedType>>
|
||||||
|
kotlin.Any
|
||||||
|
|
||||||
|
[approximated all super types]
|
||||||
|
kotlin.collections.List<kotlin.Any?>
|
||||||
|
kotlin.collections.MutableCollection<out kotlin.Any?>
|
||||||
|
kotlin.collections.Collection<kotlin.Any?>
|
||||||
|
kotlin.collections.MutableIterable<kotlin.Any?>
|
||||||
|
kotlin.collections.Iterable<kotlin.Any?>
|
||||||
|
kotlin.Any
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
val s = <expr>""</expr>
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
[direct super types]
|
||||||
|
kotlin.Comparable<kotlin.String>
|
||||||
|
kotlin.CharSequence
|
||||||
|
java.io.Serializable
|
||||||
|
|
||||||
|
[approximated direct super types]
|
||||||
|
kotlin.Comparable<kotlin.String>
|
||||||
|
kotlin.CharSequence
|
||||||
|
java.io.Serializable
|
||||||
|
|
||||||
|
[all super types]
|
||||||
|
kotlin.Comparable<kotlin.String>
|
||||||
|
kotlin.CharSequence
|
||||||
|
java.io.Serializable
|
||||||
|
kotlin.Any
|
||||||
|
|
||||||
|
[approximated all super types]
|
||||||
|
kotlin.Comparable<kotlin.String>
|
||||||
|
kotlin.CharSequence
|
||||||
|
java.io.Serializable
|
||||||
|
kotlin.Any
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
class Foo<T : List<String>>(t: T) {
|
||||||
|
val t2 = <expr>t</expr>
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
[direct super types]
|
||||||
|
kotlin.collections.List<kotlin.String>
|
||||||
|
|
||||||
|
[approximated direct super types]
|
||||||
|
kotlin.collections.List<kotlin.String>
|
||||||
|
|
||||||
|
[all super types]
|
||||||
|
kotlin.collections.List<kotlin.String>
|
||||||
|
kotlin.collections.Collection<kotlin.String>
|
||||||
|
kotlin.collections.Iterable<kotlin.String>
|
||||||
|
kotlin.Any
|
||||||
|
|
||||||
|
[approximated all super types]
|
||||||
|
kotlin.collections.List<kotlin.String>
|
||||||
|
kotlin.collections.Collection<kotlin.String>
|
||||||
|
kotlin.collections.Iterable<kotlin.String>
|
||||||
|
kotlin.Any
|
||||||
@@ -392,7 +392,7 @@ fun ConeTypeContext.captureFromArgumentsInternal(type: ConeKotlinType, status: C
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun ConeTypeContext.captureArguments(type: ConeKotlinType, status: CaptureStatus): Array<ConeKotlinType>? {
|
fun ConeTypeContext.captureArguments(type: ConeKotlinType, status: CaptureStatus): Array<ConeKotlinType>? {
|
||||||
val argumentsCount = type.typeArguments.size
|
val argumentsCount = type.typeArguments.size
|
||||||
if (argumentsCount == 0) return null
|
if (argumentsCount == 0) return null
|
||||||
|
|
||||||
|
|||||||
+4
@@ -88,6 +88,10 @@ fun main(args: Array<String>) {
|
|||||||
testClass<AbstractHasCommonSubtypeTest> {
|
testClass<AbstractHasCommonSubtypeTest> {
|
||||||
model("components/hasCommonSubtype")
|
model("components/hasCommonSubtype")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
testClass<AbstractGetSuperTypesTest> {
|
||||||
|
model("components/getSuperTypes")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
testGroup("analysis/low-level-api-fir/tests", "compiler/fir/raw-fir/psi2fir/testData") {
|
testGroup("analysis/low-level-api-fir/tests", "compiler/fir/raw-fir/psi2fir/testData") {
|
||||||
|
|||||||
Reference in New Issue
Block a user