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 4cd8bc298cb..57f0eac6dc0 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 @@ -30,7 +30,10 @@ import com.intellij.psi.util.PsiTypesUtil import org.jetbrains.kotlin.asJava.toLightClass import org.jetbrains.kotlin.asJava.toLightElements import org.jetbrains.kotlin.codegen.signature.BothSignatureWriter +import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.descriptors.FunctionDescriptor +import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.load.kotlin.TypeMappingMode import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.resolve.BindingContext @@ -78,6 +81,8 @@ internal fun KotlinType.toPsiType(source: UElement, element: KtElement, boxed: B if (psiType != null) return psiType } + if (this.containsLocalTypes()) return UastErrorType + val project = element.project val typeMapper = ServiceManager.getService(project, KotlinUastBindingContextProviderService::class.java) .getTypeMapper(element) ?: return UastErrorType @@ -95,6 +100,22 @@ internal fun KotlinType.toPsiType(source: UElement, element: KtElement, boxed: B return ClsTypeElementImpl(source.getParentOfType(false)?.psi ?: element, typeText, '\u0000').type } +private fun KotlinType.containsLocalTypes(): Boolean { + val typeDeclarationDescriptor = this.constructor.declarationDescriptor + if (typeDeclarationDescriptor is ClassDescriptor) { + val containerDescriptor = typeDeclarationDescriptor.containingDeclaration + if (containerDescriptor is PropertyDescriptor || containerDescriptor is FunctionDescriptor) { + return true + } + } + + if (arguments.any { it.type.containsLocalTypes() }) { + return true + } + + return false +} + internal fun KtTypeReference?.toPsiType(source: UElement, boxed: Boolean = false): PsiType { if (this == null) return UastErrorType return (analyze()[BindingContext.TYPE, this] ?: return UastErrorType).toPsiType(source, this, boxed)