From 42b7552d17d582879613959d97828db019d0e854 Mon Sep 17 00:00:00 2001 From: Mikhail Zarechenskiy Date: Thu, 6 Jun 2019 17:24:11 +0300 Subject: [PATCH] Fix exception on attempt to map inner non-fixed type variable #KT-31842 Fixed --- .../internal/kotlinInternalUastUtils.kt | 3 ++- .../testData/InnerNonFixedTypeVariable.kt | 6 +++++ .../InnerNonFixedTypeVariable.types.txt | 22 +++++++++++++++++++ .../uast-kotlin/tests/KotlinUastTypesTest.kt | 2 ++ 4 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 plugins/uast-kotlin/testData/InnerNonFixedTypeVariable.kt create mode 100644 plugins/uast-kotlin/testData/InnerNonFixedTypeVariable.types.txt diff --git a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/internal/kotlinInternalUastUtils.kt b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/internal/kotlinInternalUastUtils.kt index 5aec717e24e..bbd52200ac2 100644 --- a/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/internal/kotlinInternalUastUtils.kt +++ b/plugins/uast-kotlin/src/org/jetbrains/uast/kotlin/internal/kotlinInternalUastUtils.kt @@ -63,6 +63,7 @@ import org.jetbrains.kotlin.synthetic.SamAdapterExtensionFunctionDescriptor import org.jetbrains.kotlin.type.MapPsiToAsmDesc import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.typeUtil.builtIns +import org.jetbrains.kotlin.types.typeUtil.contains import org.jetbrains.kotlin.types.typeUtil.isInterface import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull import org.jetbrains.uast.* @@ -235,7 +236,7 @@ internal fun KotlinType.toPsiType(lightDeclaration: PsiModifierListOwner?, conte return typeAlias.expandedType.toPsiType(lightDeclaration, context, boxed) } - if (constructor is TypeVariableTypeConstructor) { + if (contains { type -> type.constructor is TypeVariableTypeConstructor }) { return UastErrorType } diff --git a/plugins/uast-kotlin/testData/InnerNonFixedTypeVariable.kt b/plugins/uast-kotlin/testData/InnerNonFixedTypeVariable.kt new file mode 100644 index 00000000000..ebd7a673ecd --- /dev/null +++ b/plugins/uast-kotlin/testData/InnerNonFixedTypeVariable.kt @@ -0,0 +1,6 @@ +class Some> +fun test(list: List) { + list.filterIsInstance().mapTo(mutableSetOf()) { + + } +} \ No newline at end of file diff --git a/plugins/uast-kotlin/testData/InnerNonFixedTypeVariable.types.txt b/plugins/uast-kotlin/testData/InnerNonFixedTypeVariable.types.txt new file mode 100644 index 00000000000..0f3cc47391f --- /dev/null +++ b/plugins/uast-kotlin/testData/InnerNonFixedTypeVariable.types.txt @@ -0,0 +1,22 @@ +UFile (package = ) [public final class InnerNonFixedTypeVariableKt {...] + UClass (name = InnerNonFixedTypeVariableKt) [public final class InnerNonFixedTypeVariableKt {...}] + UAnnotationMethod (name = test) [public static final fun test(@org.jetbrains.annotations.NotNull list: java.util.List) : void {...}] + UParameter (name = list) [@org.jetbrains.annotations.NotNull var list: java.util.List] + UAnnotation (fqName = org.jetbrains.annotations.NotNull) [@org.jetbrains.annotations.NotNull] + UBlockExpression [{...}] : PsiType: + UQualifiedReferenceExpression [list.filterIsInstance().(mutableSetOf(), { ...})] : PsiType: + UQualifiedReferenceExpression [list.filterIsInstance()] + USimpleNameReferenceExpression (identifier = list) [list] : PsiType:List + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) [filterIsInstance()] + UIdentifier (Identifier (filterIsInstance)) [UIdentifier (Identifier (filterIsInstance))] + USimpleNameReferenceExpression (identifier = filterIsInstance, resolvesTo = null) [filterIsInstance] + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 2)) [(mutableSetOf(), { ...})] : PsiType: + UIdentifier (Identifier (mapTo)) [UIdentifier (Identifier (mapTo))] + USimpleNameReferenceExpression (identifier = , resolvesTo = null) [] : PsiType: + UCallExpression (kind = UastCallKind(name='method_call'), argCount = 0)) [mutableSetOf()] : PsiType: + UIdentifier (Identifier (mutableSetOf)) [UIdentifier (Identifier (mutableSetOf))] + USimpleNameReferenceExpression (identifier = mutableSetOf, resolvesTo = null) [mutableSetOf] : PsiType: + ULambdaExpression [{ ...}] : PsiType:Function0 + UBlockExpression [{...}] + UClass (name = Some) [public final class Some {...}] + UAnnotationMethod (name = Some) [public fun Some() = UastEmptyExpression] diff --git a/plugins/uast-kotlin/tests/KotlinUastTypesTest.kt b/plugins/uast-kotlin/tests/KotlinUastTypesTest.kt index 25adfb0b941..f041d88953a 100644 --- a/plugins/uast-kotlin/tests/KotlinUastTypesTest.kt +++ b/plugins/uast-kotlin/tests/KotlinUastTypesTest.kt @@ -16,4 +16,6 @@ class KotlinUastTypesTest : AbstractKotlinTypesTest() { @Test fun testStringTemplateComplex() = doTest("StringTemplateComplex") @Test fun testInferenceInsideUnresolvedConstructor() = doTest("InferenceInsideUnresolvedConstructor") + + @Test fun testInnerNonFixedTypeVariable() = doTest("InnerNonFixedTypeVariable") } \ No newline at end of file