AA: handle underscore as type arguments

^KTIJ-24742 Fixed
This commit is contained in:
Jinseong Jeon
2023-02-21 17:40:32 -08:00
committed by Ilya Kirillov
parent d73d3c46e2
commit 5455942859
23 changed files with 537 additions and 7 deletions
@@ -30,12 +30,15 @@ import org.jetbrains.kotlin.analysis.api.lifetime.withValidityAssertion
import org.jetbrains.kotlin.config.LanguageFeature
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.name.StandardClassIds
import org.jetbrains.kotlin.psi.KtCallElement
import org.jetbrains.kotlin.psi.KtDoubleColonExpression
import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.psi.KtTypeReference
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.calls.inference.CapturedType
import org.jetbrains.kotlin.resolve.calls.util.getResolvedCall
import org.jetbrains.kotlin.resolve.scopes.utils.getImplicitReceiversHierarchy
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.checker.NewCapturedType
@@ -65,18 +68,19 @@ internal class KtFe10TypeProvider(
override fun approximateToSuperPublicDenotableType(type: KtType, approximateLocalTypes: Boolean): KtType? {
require(type is KtFe10Type)
return typeApproximator.approximateToSuperType(type.fe10Type, PublicApproximatorConfiguration(approximateLocalTypes))?.toKtType(analysisContext)
return typeApproximator.approximateToSuperType(type.fe10Type, PublicApproximatorConfiguration(approximateLocalTypes))
?.toKtType(analysisContext)
}
override fun approximateToSubPublicDenotableType(type: KtType, approximateLocalTypes: Boolean): KtType? {
require(type is KtFe10Type)
return typeApproximator.approximateToSubType(type.fe10Type, PublicApproximatorConfiguration(approximateLocalTypes))?.toKtType(analysisContext)
return typeApproximator.approximateToSubType(type.fe10Type, PublicApproximatorConfiguration(approximateLocalTypes))
?.toKtType(analysisContext)
}
override fun buildSelfClassType(symbol: KtNamedClassOrObjectSymbol): KtType {
val kotlinType = (getSymbolDescriptor(symbol) as? ClassDescriptor)?.defaultType
?: ErrorUtils.createErrorType(ErrorTypeKind.UNRESOLVED_CLASS_TYPE, symbol.nameOrAnonymous.toString())
return kotlinType.toKtType(analysisContext)
}
@@ -88,10 +92,21 @@ internal class KtFe10TypeProvider(
override fun getKtType(ktTypeReference: KtTypeReference): KtType {
val bindingContext = analysisContext.analyze(ktTypeReference, AnalysisMode.PARTIAL)
val kotlinType = bindingContext[BindingContext.TYPE, ktTypeReference]
?: getKtTypeAsTypeArgument(ktTypeReference)
?: ErrorUtils.createErrorType(ErrorTypeKind.UNRESOLVED_TYPE, ktTypeReference.text)
return kotlinType.toKtType(analysisContext)
}
private fun getKtTypeAsTypeArgument(ktTypeReference: KtTypeReference): KotlinType? {
val call = ktTypeReference.getParentOfType<KtCallElement>(strict = true) ?: return null
val bindingContext = analysisContext.analyze(ktTypeReference, AnalysisMode.PARTIAL)
val resolvedCall = call.getResolvedCall(bindingContext) ?: return null
val typeProjection = call.typeArguments.find { it.typeReference == ktTypeReference } ?: return null
val index = call.typeArguments.indexOf(typeProjection)
val paramDescriptor = resolvedCall.candidateDescriptor.typeParameters.find { it.index == index } ?: return null
return resolvedCall.typeArguments[paramDescriptor]
}
override fun getReceiverTypeForDoubleColonExpression(expression: KtDoubleColonExpression): KtType? {
val bindingContext = analysisContext.analyze(expression, AnalysisMode.PARTIAL)
val lhs = bindingContext[BindingContext.DOUBLE_COLON_LHS, expression] ?: return null
@@ -0,0 +1,90 @@
/*
* Copyright 2010-2023 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.fe10.test.cases.generated.cases.components.typeProvider;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.analysis.api.fe10.test.configurator.AnalysisApiFe10TestConfiguratorFactory;
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisApiTestConfiguratorFactoryData;
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisApiTestConfigurator;
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.TestModuleKind;
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.FrontendKind;
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisSessionMode;
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisApiMode;
import org.jetbrains.kotlin.analysis.api.impl.base.test.cases.components.typeProvider.AbstractTypeReferenceTest;
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 org.jetbrains.kotlin.generators.tests.analysis.api.GenerateAnalysisApiTestsKt}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("analysis/analysis-api/testData/components/typeProvider/typeReference")
@TestDataPath("$PROJECT_ROOT")
public class Fe10IdeNormalAnalysisSourceModuleTypeReferenceTestGenerated extends AbstractTypeReferenceTest {
@NotNull
@Override
public AnalysisApiTestConfigurator getConfigurator() {
return AnalysisApiFe10TestConfiguratorFactory.INSTANCE.createConfigurator(
new AnalysisApiTestConfiguratorFactoryData(
FrontendKind.Fe10,
TestModuleKind.Source,
AnalysisSessionMode.Normal,
AnalysisApiMode.Ide
)
);
}
@Test
public void testAllFilesPresentInTypeReference() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/typeProvider/typeReference"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@Test
@TestMetadata("starProjection.kt")
public void testStarProjection() throws Exception {
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/starProjection.kt");
}
@Test
@TestMetadata("superTypeEntry.kt")
public void testSuperTypeEntry() throws Exception {
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/superTypeEntry.kt");
}
@Test
@TestMetadata("superTypeEntry_withTypeArgument.kt")
public void testSuperTypeEntry_withTypeArgument() throws Exception {
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/superTypeEntry_withTypeArgument.kt");
}
@Test
@TestMetadata("typeArgument_functionCall.kt")
public void testTypeArgument_functionCall() throws Exception {
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/typeArgument_functionCall.kt");
}
@Test
@TestMetadata("typeArgument_superTypeEntry.kt")
public void testTypeArgument_superTypeEntry() throws Exception {
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/typeArgument_superTypeEntry.kt");
}
@Test
@TestMetadata("underscoreTypeArgument_inferred.kt")
public void testUnderscoreTypeArgument_inferred() throws Exception {
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/underscoreTypeArgument_inferred.kt");
}
@Test
@TestMetadata("underscoreTypeArgument_reified.kt")
public void testUnderscoreTypeArgument_reified() throws Exception {
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/underscoreTypeArgument_reified.kt");
}
}
@@ -97,6 +97,12 @@ internal class KtFirTypeProvider(
return when (val fir = ktTypeReference.getOrBuildFir(firResolveSession)) {
is FirResolvedTypeRef -> fir.coneType.asKtType()
is FirDelegatedConstructorCall -> fir.constructedTypeRef.coneType.asKtType()
is FirTypeProjectionWithVariance -> {
when (val typeRef = fir.typeRef) {
is FirResolvedTypeRef -> typeRef.coneType.asKtType()
else -> throwUnexpectedFirElementError(fir, ktTypeReference)
}
}
else -> throwUnexpectedFirElementError(fir, ktTypeReference)
}
}
@@ -0,0 +1,90 @@
/*
* Copyright 2010-2023 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.test.cases.generated.cases.components.typeProvider;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.analysis.api.fir.test.configurators.AnalysisApiFirTestConfiguratorFactory;
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisApiTestConfiguratorFactoryData;
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisApiTestConfigurator;
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.TestModuleKind;
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.FrontendKind;
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisSessionMode;
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisApiMode;
import org.jetbrains.kotlin.analysis.api.impl.base.test.cases.components.typeProvider.AbstractTypeReferenceTest;
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 org.jetbrains.kotlin.generators.tests.analysis.api.GenerateAnalysisApiTestsKt}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("analysis/analysis-api/testData/components/typeProvider/typeReference")
@TestDataPath("$PROJECT_ROOT")
public class FirIdeDependentAnalysisSourceModuleTypeReferenceTestGenerated extends AbstractTypeReferenceTest {
@NotNull
@Override
public AnalysisApiTestConfigurator getConfigurator() {
return AnalysisApiFirTestConfiguratorFactory.INSTANCE.createConfigurator(
new AnalysisApiTestConfiguratorFactoryData(
FrontendKind.Fir,
TestModuleKind.Source,
AnalysisSessionMode.Dependent,
AnalysisApiMode.Ide
)
);
}
@Test
public void testAllFilesPresentInTypeReference() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/typeProvider/typeReference"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@Test
@TestMetadata("starProjection.kt")
public void testStarProjection() throws Exception {
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/starProjection.kt");
}
@Test
@TestMetadata("superTypeEntry.kt")
public void testSuperTypeEntry() throws Exception {
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/superTypeEntry.kt");
}
@Test
@TestMetadata("superTypeEntry_withTypeArgument.kt")
public void testSuperTypeEntry_withTypeArgument() throws Exception {
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/superTypeEntry_withTypeArgument.kt");
}
@Test
@TestMetadata("typeArgument_functionCall.kt")
public void testTypeArgument_functionCall() throws Exception {
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/typeArgument_functionCall.kt");
}
@Test
@TestMetadata("typeArgument_superTypeEntry.kt")
public void testTypeArgument_superTypeEntry() throws Exception {
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/typeArgument_superTypeEntry.kt");
}
@Test
@TestMetadata("underscoreTypeArgument_inferred.kt")
public void testUnderscoreTypeArgument_inferred() throws Exception {
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/underscoreTypeArgument_inferred.kt");
}
@Test
@TestMetadata("underscoreTypeArgument_reified.kt")
public void testUnderscoreTypeArgument_reified() throws Exception {
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/underscoreTypeArgument_reified.kt");
}
}
@@ -0,0 +1,90 @@
/*
* Copyright 2010-2023 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.test.cases.generated.cases.components.typeProvider;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.analysis.api.fir.test.configurators.AnalysisApiFirTestConfiguratorFactory;
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisApiTestConfiguratorFactoryData;
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisApiTestConfigurator;
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.TestModuleKind;
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.FrontendKind;
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisSessionMode;
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisApiMode;
import org.jetbrains.kotlin.analysis.api.impl.base.test.cases.components.typeProvider.AbstractTypeReferenceTest;
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 org.jetbrains.kotlin.generators.tests.analysis.api.GenerateAnalysisApiTestsKt}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("analysis/analysis-api/testData/components/typeProvider/typeReference")
@TestDataPath("$PROJECT_ROOT")
public class FirIdeNormalAnalysisSourceModuleTypeReferenceTestGenerated extends AbstractTypeReferenceTest {
@NotNull
@Override
public AnalysisApiTestConfigurator getConfigurator() {
return AnalysisApiFirTestConfiguratorFactory.INSTANCE.createConfigurator(
new AnalysisApiTestConfiguratorFactoryData(
FrontendKind.Fir,
TestModuleKind.Source,
AnalysisSessionMode.Normal,
AnalysisApiMode.Ide
)
);
}
@Test
public void testAllFilesPresentInTypeReference() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/typeProvider/typeReference"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@Test
@TestMetadata("starProjection.kt")
public void testStarProjection() throws Exception {
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/starProjection.kt");
}
@Test
@TestMetadata("superTypeEntry.kt")
public void testSuperTypeEntry() throws Exception {
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/superTypeEntry.kt");
}
@Test
@TestMetadata("superTypeEntry_withTypeArgument.kt")
public void testSuperTypeEntry_withTypeArgument() throws Exception {
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/superTypeEntry_withTypeArgument.kt");
}
@Test
@TestMetadata("typeArgument_functionCall.kt")
public void testTypeArgument_functionCall() throws Exception {
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/typeArgument_functionCall.kt");
}
@Test
@TestMetadata("typeArgument_superTypeEntry.kt")
public void testTypeArgument_superTypeEntry() throws Exception {
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/typeArgument_superTypeEntry.kt");
}
@Test
@TestMetadata("underscoreTypeArgument_inferred.kt")
public void testUnderscoreTypeArgument_inferred() throws Exception {
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/underscoreTypeArgument_inferred.kt");
}
@Test
@TestMetadata("underscoreTypeArgument_reified.kt")
public void testUnderscoreTypeArgument_reified() throws Exception {
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/underscoreTypeArgument_reified.kt");
}
}
@@ -0,0 +1,31 @@
/*
* Copyright 2010-2023 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.impl.base.test.cases.components.typeProvider
import org.jetbrains.kotlin.analysis.test.framework.base.AbstractAnalysisApiSingleFileTest
import org.jetbrains.kotlin.analysis.test.framework.services.expressionMarkerProvider
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi.KtTypeReference
import org.jetbrains.kotlin.test.model.TestModule
import org.jetbrains.kotlin.test.services.TestServices
import org.jetbrains.kotlin.test.services.assertions
import org.jetbrains.kotlin.types.Variance
abstract class AbstractTypeReferenceTest : AbstractAnalysisApiSingleFileTest() {
override fun doTestByFileStructure(ktFile: KtFile, module: TestModule, testServices: TestServices) {
val expressionAtCaret = testServices.expressionMarkerProvider.getElementOfTypeAtCaret(ktFile) as KtTypeReference
val actual = analyseForTest(expressionAtCaret) {
val ktType = expressionAtCaret.getKtType()
buildString {
appendLine("expression: ${expressionAtCaret.text}")
appendLine("ktType: ${ktType.render(position = Variance.INVARIANT)}")
}
}
testServices.assertions.assertEqualsToTestDataFileSibling(actual)
}
}
@@ -0,0 +1,90 @@
/*
* Copyright 2010-2023 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.standalone.fir.test.cases.generated.cases.components.typeProvider;
import com.intellij.testFramework.TestDataPath;
import org.jetbrains.kotlin.test.util.KtTestUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.analysis.api.standalone.fir.test.AnalysisApiFirStandaloneModeTestConfiguratorFactory;
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisApiTestConfiguratorFactoryData;
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisApiTestConfigurator;
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.TestModuleKind;
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.FrontendKind;
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisSessionMode;
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisApiMode;
import org.jetbrains.kotlin.analysis.api.impl.base.test.cases.components.typeProvider.AbstractTypeReferenceTest;
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 org.jetbrains.kotlin.generators.tests.analysis.api.GenerateAnalysisApiTestsKt}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("analysis/analysis-api/testData/components/typeProvider/typeReference")
@TestDataPath("$PROJECT_ROOT")
public class FirStandaloneNormalAnalysisSourceModuleTypeReferenceTestGenerated extends AbstractTypeReferenceTest {
@NotNull
@Override
public AnalysisApiTestConfigurator getConfigurator() {
return AnalysisApiFirStandaloneModeTestConfiguratorFactory.INSTANCE.createConfigurator(
new AnalysisApiTestConfiguratorFactoryData(
FrontendKind.Fir,
TestModuleKind.Source,
AnalysisSessionMode.Normal,
AnalysisApiMode.Standalone
)
);
}
@Test
public void testAllFilesPresentInTypeReference() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("analysis/analysis-api/testData/components/typeProvider/typeReference"), Pattern.compile("^(.+)\\.kt$"), null, true);
}
@Test
@TestMetadata("starProjection.kt")
public void testStarProjection() throws Exception {
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/starProjection.kt");
}
@Test
@TestMetadata("superTypeEntry.kt")
public void testSuperTypeEntry() throws Exception {
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/superTypeEntry.kt");
}
@Test
@TestMetadata("superTypeEntry_withTypeArgument.kt")
public void testSuperTypeEntry_withTypeArgument() throws Exception {
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/superTypeEntry_withTypeArgument.kt");
}
@Test
@TestMetadata("typeArgument_functionCall.kt")
public void testTypeArgument_functionCall() throws Exception {
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/typeArgument_functionCall.kt");
}
@Test
@TestMetadata("typeArgument_superTypeEntry.kt")
public void testTypeArgument_superTypeEntry() throws Exception {
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/typeArgument_superTypeEntry.kt");
}
@Test
@TestMetadata("underscoreTypeArgument_inferred.kt")
public void testUnderscoreTypeArgument_inferred() throws Exception {
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/underscoreTypeArgument_inferred.kt");
}
@Test
@TestMetadata("underscoreTypeArgument_reified.kt")
public void testUnderscoreTypeArgument_reified() throws Exception {
runTest("analysis/analysis-api/testData/components/typeProvider/typeReference/underscoreTypeArgument_reified.kt");
}
}
@@ -49,19 +49,19 @@ public interface KtTypeProviderMixIn : KtAnalysisSessionMixIn {
get() = withValidityAssertion { analysisSession.typeProvider.builtinTypes }
/**
* Approximates [KtType] with the a supertype which can be rendered in a source code
* Approximates [KtType] with a supertype which can be rendered in a source code
*
* Return `null` if the type do not need approximation and can be rendered as is
* Otherwise, for type `T` return type `S` such `T <: S` and `T` and every it type argument is denotable
* Otherwise, for type `T` return type `S` such `T <: S` and `T` and every type argument is denotable
*/
public fun KtType.approximateToSuperPublicDenotable(approximateLocalTypes: Boolean): KtType? =
withValidityAssertion { analysisSession.typeProvider.approximateToSuperPublicDenotableType(this, approximateLocalTypes) }
/**
* Approximates [KtType] with the a subtype which can be rendered in a source code
* Approximates [KtType] with a subtype which can be rendered in a source code
*
* Return `null` if the type do not need approximation and can be rendered as is
* Otherwise, for type `T` return type `S` such `S <: T` and `T` and every it type argument is denotable
* Otherwise, for type `T` return type `S` such `S <: T` and `T` and every type argument is denotable
*/
public fun KtType.approximateToSubPublicDenotable(approximateLocalTypes: Boolean): KtType? =
withValidityAssertion { analysisSession.typeProvider.approximateToSubPublicDenotableType(this, approximateLocalTypes) }
@@ -0,0 +1,12 @@
abstract class Base<T> {
abstract foo(arg: T): T
}
class StringSub : Base<String> {
override fun foo(arg: String) = arg + " = 42"
}
fun test() {
val x : Base<<caret>*> = StringSub()
x.foo("42")
}
@@ -0,0 +1,2 @@
expression: Base<*>
ktType: Base<*>
@@ -0,0 +1,3 @@
open class Base
class Sub : Bas<caret>e()
@@ -0,0 +1,2 @@
expression: Base
ktType: Base
@@ -0,0 +1,7 @@
abstract class Base<T> {
abstract foo(arg: T): T
}
class StringSub : B<caret>ase<String> {
override fun foo(arg: String) = arg + " = 42"
}
@@ -0,0 +1,2 @@
expression: Base<String>
ktType: Base<kotlin.String>
@@ -0,0 +1,7 @@
inline fun <T> foo(arg: T) {
println(arg.toString())
}
fun test() {
foo<Strin<caret>g>("42")
}
@@ -0,0 +1,2 @@
expression: String
ktType: kotlin.String
@@ -0,0 +1,7 @@
abstract class Base<T> {
abstract foo(arg: T): T
}
class StringSub : Base<Strin<caret>g> {
override fun foo(arg: String) = arg + " = 42"
}
@@ -0,0 +1,2 @@
expression: String
ktType: kotlin.String
@@ -0,0 +1,32 @@
// example from https://kotlinlang.org/docs/generics.html#underscore-operator-for-type-arguments
// modified to avoid using reflection (::class.java)
abstract class SomeClass<T> {
abstract fun execute() : T
}
class SomeImplementation : SomeClass<String>() {
override fun execute(): String = "Test"
}
class OtherImplementation : SomeClass<Int>() {
override fun execute(): Int = 42
}
object Runner {
inline fun <reified S: SomeClass<T>, T> run(instance: S) : T {
return instance.execute()
}
}
fun test() {
val i = SomeImplementation()
// T is inferred as String because SomeImplementation derives from SomeClass<String>
val s = Runner.run<_, _>(i)
assert(s == "Test")
val j = OtherImplementation()
// T is inferred as Int because OtherImplementation derives from SomeClass<Int>
val n = Runner.run<_, <caret>_>(j)
assert(n == 42)
}
@@ -0,0 +1,2 @@
expression: _
ktType: kotlin.Int
@@ -0,0 +1,32 @@
// example from https://kotlinlang.org/docs/generics.html#underscore-operator-for-type-arguments
// modified to avoid using reflection (::class.java)
abstract class SomeClass<T> {
abstract fun execute() : T
}
class SomeImplementation : SomeClass<String>() {
override fun execute(): String = "Test"
}
class OtherImplementation : SomeClass<Int>() {
override fun execute(): Int = 42
}
object Runner {
inline fun <reified S: SomeClass<T>, T> run(instance: S) : T {
return instance.execute()
}
}
fun test() {
val i = SomeImplementation()
// T is inferred as String because SomeImplementation derives from SomeClass<String>
val s = Runner.run<_, _>(i)
assert(s == "Test")
val j = OtherImplementation()
// T is inferred as Int because OtherImplementation derives from SomeClass<Int>
val n = Runner.run<<caret>_, _>(j)
assert(n == 42)
}
@@ -0,0 +1,2 @@
expression: _
ktType: OtherImplementation
@@ -43,6 +43,7 @@ import org.jetbrains.kotlin.analysis.api.impl.base.test.cases.components.typeInf
import org.jetbrains.kotlin.analysis.api.impl.base.test.cases.components.typeInfoProvider.AbstractIsDenotableTest
import org.jetbrains.kotlin.analysis.api.impl.base.test.cases.components.typeProvider.AbstractAnalysisApiGetSuperTypesTest
import org.jetbrains.kotlin.analysis.api.impl.base.test.cases.components.typeProvider.AbstractHasCommonSubtypeTest
import org.jetbrains.kotlin.analysis.api.impl.base.test.cases.components.typeProvider.AbstractTypeReferenceTest
import org.jetbrains.kotlin.analysis.api.impl.base.test.cases.references.AbstractReferenceResolveTest
import org.jetbrains.kotlin.analysis.api.impl.base.test.cases.references.AbstractReferenceShortenerTest
import org.jetbrains.kotlin.analysis.api.impl.base.test.cases.scopes.*
@@ -369,6 +370,9 @@ private fun AnalysisApiTestGroup.generateAnalysisApiComponentsTests() {
model("haveCommonSubtype")
}
}
test(AbstractTypeReferenceTest::class) {
model("typeReference")
}
}
component("signatureSubstitution") {