Gracefully handle erroneous super type during local type approximation
^KTIJ-23528 Fixed
This commit is contained in:
committed by
Ilya Kirillov
parent
f775778efa
commit
c79d65536b
+6
@@ -58,6 +58,12 @@ public class FirIdeDependentAnalysisSourceModuleAnalysisApiExpressionPsiTypeProv
|
||||
runTest("analysis/analysis-api/testData/components/psiTypeProvider/psiType/forExpression/class_object_constructor.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("localClassWithUnresolvedSuperType.kt")
|
||||
public void testLocalClassWithUnresolvedSuperType() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/psiTypeProvider/psiType/forExpression/localClassWithUnresolvedSuperType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeParamFlexibleUpperBound.kt")
|
||||
public void testTypeParamFlexibleUpperBound() throws Exception {
|
||||
|
||||
+6
@@ -58,6 +58,12 @@ public class FirIdeNormalAnalysisSourceModuleAnalysisApiExpressionPsiTypeProvide
|
||||
runTest("analysis/analysis-api/testData/components/psiTypeProvider/psiType/forExpression/class_object_constructor.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("localClassWithUnresolvedSuperType.kt")
|
||||
public void testLocalClassWithUnresolvedSuperType() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/psiTypeProvider/psiType/forExpression/localClassWithUnresolvedSuperType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeParamFlexibleUpperBound.kt")
|
||||
public void testTypeParamFlexibleUpperBound() throws Exception {
|
||||
|
||||
+11
-2
@@ -6,8 +6,12 @@
|
||||
package org.jetbrains.kotlin.analysis.api.impl.base.test.cases.components.psiTypeProvider
|
||||
|
||||
import org.jetbrains.kotlin.analysis.api.analyze
|
||||
import org.jetbrains.kotlin.analysis.api.impl.base.test.cases.components.psiTypeProvider.AnalysisApiPsiTypeProviderTestUtils.findLightDeclarationContext
|
||||
import org.jetbrains.kotlin.analysis.api.impl.base.test.cases.components.psiTypeProvider.AnalysisApiPsiTypeProviderTestUtils.getContainingKtLightClass
|
||||
import org.jetbrains.kotlin.analysis.test.framework.base.AbstractAnalysisApiSingleFileTest
|
||||
import org.jetbrains.kotlin.analysis.test.framework.services.expressionMarkerProvider
|
||||
import org.jetbrains.kotlin.analysis.utils.printer.parentOfType
|
||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtExpression
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
@@ -15,13 +19,18 @@ import org.jetbrains.kotlin.test.services.TestServices
|
||||
import org.jetbrains.kotlin.test.services.assertions
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
|
||||
abstract class AbstractAnalysisApiExpressionPsiTypeProviderTest : AbstractAnalysisApiSingleFileTest(){
|
||||
abstract class AbstractAnalysisApiExpressionPsiTypeProviderTest : AbstractAnalysisApiSingleFileTest() {
|
||||
override fun doTestByFileStructure(ktFile: KtFile, module: TestModule, testServices: TestServices) {
|
||||
val declarationAtCaret = testServices.expressionMarkerProvider.getSelectedElement(ktFile) as KtExpression
|
||||
val containingDeclaration = declarationAtCaret.parentOfType<KtDeclaration>()
|
||||
?: error("Can't find containing declaration for $declarationAtCaret")
|
||||
val containingClass = getContainingKtLightClass(containingDeclaration, ktFile)
|
||||
val psiContext = containingClass.findLightDeclarationContext(containingDeclaration)
|
||||
?: error("Can't find psi context for $containingDeclaration")
|
||||
val actual = analyze(ktFile) {
|
||||
val returnType = declarationAtCaret.getKtType()
|
||||
?: error("Not a typable expression ${declarationAtCaret::class} ${declarationAtCaret.text}")
|
||||
val psiType = returnType.asPsiType(declarationAtCaret)
|
||||
val psiType = returnType.asPsiType(psiContext)
|
||||
buildString {
|
||||
appendLine("KtType: ${returnType.render(position = Variance.INVARIANT)}")
|
||||
appendLine("PsiType: $psiType")
|
||||
|
||||
+6
@@ -58,6 +58,12 @@ public class FirStandaloneNormalAnalysisSourceModuleAnalysisApiExpressionPsiType
|
||||
runTest("analysis/analysis-api/testData/components/psiTypeProvider/psiType/forExpression/class_object_constructor.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("localClassWithUnresolvedSuperType.kt")
|
||||
public void testLocalClassWithUnresolvedSuperType() throws Exception {
|
||||
runTest("analysis/analysis-api/testData/components/psiTypeProvider/psiType/forExpression/localClassWithUnresolvedSuperType.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("typeParamFlexibleUpperBound.kt")
|
||||
public void testTypeParamFlexibleUpperBound() throws Exception {
|
||||
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fun box() {
|
||||
class Foo {
|
||||
fun foo() {
|
||||
<expr>Bar()</expr>.unknown()
|
||||
}
|
||||
|
||||
private inner class Bar: Unknown<Unit, Unit, Int>() {
|
||||
override fun unknown() {}
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
@@ -0,0 +1,2 @@
|
||||
KtType: Foo
|
||||
PsiType: PsiType:Bar
|
||||
+2
-2
@@ -179,8 +179,8 @@ abstract class AbstractTypeApproximator(
|
||||
errorTypesEqualToAnything = false,
|
||||
stubTypesEqualToAnything = false
|
||||
)
|
||||
return AbstractTypeChecker.findCorrespondingSupertypes(typeCheckerContext, type, superConstructor).first()
|
||||
.withNullability(type.isMarkedNullable())
|
||||
return AbstractTypeChecker.findCorrespondingSupertypes(typeCheckerContext, type, superConstructor).firstOrNull()
|
||||
?.withNullability(type.isMarkedNullable())
|
||||
}
|
||||
|
||||
private fun isIntersectionTypeEffectivelyNothing(constructor: IntersectionTypeConstructorMarker): Boolean {
|
||||
|
||||
Reference in New Issue
Block a user