Uast: Fix an exception while converting type alias KotlinType to PsiType (KT-21874)

This commit is contained in:
Yan Zhulanow
2018-02-07 18:20:31 +03:00
parent 1cc4744345
commit 03a20384ef
3 changed files with 19 additions and 0 deletions
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.builtins.isBuiltinFunctionalTypeOrSubtype
import org.jetbrains.kotlin.codegen.signature.BothSignatureWriter
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor
import org.jetbrains.kotlin.load.kotlin.TypeMappingMode
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.BindingContext
@@ -74,6 +75,10 @@ internal fun <T> lz(initializer: () -> T) = lazy(LazyThreadSafetyMode.NONE, init
internal fun KotlinType.toPsiType(source: UElement, element: KtElement, boxed: Boolean): PsiType {
if (this.isError) return UastErrorType
(constructor.declarationDescriptor as? TypeAliasDescriptor)?.let { typeAlias ->
return typeAlias.expandedType.toPsiType(source, element, boxed)
}
if (arguments.isEmpty()) {
val typeFqName = this.constructor.declarationDescriptor?.fqNameSafe?.asString()
fun PsiPrimitiveType.orBoxed() = if (boxed) getBoxedType(element) else this
+3
View File
@@ -0,0 +1,3 @@
class A
typealias F = A.(A) -> A
typealias G = (F) -> F
@@ -6,6 +6,7 @@ import com.intellij.testFramework.UsefulTestCase
import org.jetbrains.kotlin.asJava.toLightAnnotation
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
import org.jetbrains.kotlin.psi.psiUtil.getValueParameterList
import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase
import org.jetbrains.kotlin.utils.addToStdlib.cast
import org.jetbrains.uast.*
@@ -277,6 +278,16 @@ class KotlinUastApiTest : AbstractKotlinUastTest() {
}
}
@Test
fun testTypeAliases() {
doTest("TypeAliases") { _, file ->
val g = (file.psi as KtFile).declarations.single { it.name == "G" } as KtTypeAlias
val originalType = g.getTypeReference()!!.typeElement as KtFunctionType
val originalTypeParameters = originalType.parameterList.toUElement() as UDeclarationsExpression
Assert.assertTrue((originalTypeParameters.declarations.single() as UParameter).type.isValid)
}
}
@Test
fun testNestedAnnotation() = doTest("AnnotationComplex") { _, file ->
file.findElementByTextFromPsi<UElement>("@AnnotationArray(value = Annotation())")