Fix exception from UAST on attempt to map non-fixed type variable

#KT-31723 Fixed
 #EA-126269 Fixed
 #EA-143705 Fixed
 #EA-143703 Fixed
 #EA-143694 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2019-05-31 14:12:58 +03:00
parent 91bd11a6db
commit e15cb67e29
4 changed files with 29 additions and 0 deletions
@@ -50,6 +50,7 @@ import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
import org.jetbrains.kotlin.resolve.calls.inference.model.TypeVariableTypeConstructor
import org.jetbrains.kotlin.resolve.calls.model.ArgumentMatch
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.kotlin.resolve.calls.tower.NewResolvedCallImpl
@@ -234,6 +235,10 @@ internal fun KotlinType.toPsiType(lightDeclaration: PsiModifierListOwner?, conte
return typeAlias.expandedType.toPsiType(lightDeclaration, context, boxed)
}
if (constructor is TypeVariableTypeConstructor) {
return UastErrorType
}
(constructor.declarationDescriptor as? TypeParameterDescriptor)?.let { typeParameter ->
(typeParameter.containingDeclaration.toSource()?.getMaybeLightElement() as? PsiTypeParameterListOwner)
?.typeParameterList?.typeParameters?.getOrNull(typeParameter.index)
@@ -0,0 +1,4 @@
val bar: Any
get() = Unresolved(id(42))
fun <T> id(x: T): T = x
@@ -0,0 +1,18 @@
UFile (package = ) [public final class InferenceInsideUnresolvedConstructorKt {...]
UClass (name = InferenceInsideUnresolvedConstructorKt) [public final class InferenceInsideUnresolvedConstructorKt {...}]
UAnnotationMethod (name = getBar) [public static final fun getBar() : java.lang.Object {...}]
UBlockExpression [{...}]
UReturnExpression [return <anonymous class>(id(42))]
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) [<anonymous class>(id(42))]
UIdentifier (Identifier (Unresolved)) [UIdentifier (Identifier (Unresolved))]
USimpleNameReferenceExpression (identifier = <anonymous class>, resolvesTo = null) [<anonymous class>]
UCallExpression (kind = UastCallKind(name='method_call'), argCount = 1)) [id(42)] : PsiType:<ErrorType>
UIdentifier (Identifier (id)) [UIdentifier (Identifier (id))]
USimpleNameReferenceExpression (identifier = id, resolvesTo = null) [id] : PsiType:<ErrorType>
ULiteralExpression (value = 42) [42] : PsiType:int
UAnnotationMethod (name = id) [public static final fun id(@org.jetbrains.annotations.Nullable x: T) : T {...}]
UParameter (name = x) [@org.jetbrains.annotations.Nullable var x: T]
UAnnotation (fqName = org.jetbrains.annotations.Nullable) [@org.jetbrains.annotations.Nullable]
UBlockExpression [{...}]
UReturnExpression [return x]
USimpleNameReferenceExpression (identifier = x) [x] : PsiType:T
@@ -14,4 +14,6 @@ class KotlinUastTypesTest : AbstractKotlinTypesTest() {
@Test fun testStringTemplate() = doTest("StringTemplate")
@Test fun testStringTemplateComplex() = doTest("StringTemplateComplex")
@Test fun testInferenceInsideUnresolvedConstructor() = doTest("InferenceInsideUnresolvedConstructor")
}