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 9e43f412f48..c1d06132e24 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 @@ -34,9 +34,11 @@ import org.jetbrains.kotlin.asJava.toLightClass import org.jetbrains.kotlin.asJava.toLightElements import org.jetbrains.kotlin.builtins.isBuiltinFunctionalTypeOrSubtype import org.jetbrains.kotlin.codegen.signature.BothSignatureWriter +import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor +import org.jetbrains.kotlin.idea.project.languageVersionSettings import org.jetbrains.kotlin.load.kotlin.TypeMappingMode import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.resolve.BindingContext @@ -46,6 +48,7 @@ import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall import org.jetbrains.kotlin.resolve.constants.IntegerValueTypeConstructor import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe import org.jetbrains.kotlin.types.KotlinType +import org.jetbrains.kotlin.types.TypeApproximator import org.jetbrains.kotlin.types.isError import org.jetbrains.kotlin.types.typeUtil.isInterface import org.jetbrains.uast.* @@ -112,7 +115,8 @@ internal fun KotlinType.toPsiType(source: UElement, element: KtElement, boxed: B val signatureWriter = BothSignatureWriter(BothSignatureWriter.Mode.TYPE) val typeMappingMode = if (boxed) TypeMappingMode.GENERIC_ARGUMENT else TypeMappingMode.DEFAULT - typeMapper.mapType(this, signatureWriter, typeMappingMode) + val approximatedType = TypeApproximator().approximateDeclarationType(this, true, element.languageVersionSettings) + typeMapper.mapType(approximatedType, signatureWriter, typeMappingMode) val signature = StringCharacterIterator(signatureWriter.toString()) diff --git a/plugins/uast-kotlin/tests/KotlinDetachedUastTest.kt b/plugins/uast-kotlin/tests/KotlinDetachedUastTest.kt index 561ec9535ea..b8fa9b4c7c6 100644 --- a/plugins/uast-kotlin/tests/KotlinDetachedUastTest.kt +++ b/plugins/uast-kotlin/tests/KotlinDetachedUastTest.kt @@ -26,12 +26,10 @@ import org.jetbrains.kotlin.idea.core.copied import org.jetbrains.kotlin.idea.test.KotlinLightCodeInsightFixtureTestCase import org.jetbrains.kotlin.idea.test.KotlinWithJdkAndRuntimeLightProjectDescriptor import org.jetbrains.kotlin.psi.KtCallExpression -import org.jetbrains.kotlin.psi.KtClass import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.KtPsiFactory import org.jetbrains.kotlin.psi.psiUtil.findDescendantOfType import org.jetbrains.kotlin.psi.psiUtil.getParentOfType -import org.jetbrains.kotlin.test.testFramework.runWriteAction import org.jetbrains.uast.* import org.jetbrains.uast.test.env.findUElementByTextFromPsi @@ -82,6 +80,26 @@ class KotlinDetachedUastTest : KotlinLightCodeInsightFixtureTestCase() { TestCase.assertNull(uCallExpression.methodName) } + fun testCapturedTypeInExtensionReceiverOfCall() { + val psiFile = myFixture.configureByText( + "foo.kt", """ + class Foo + + fun K.extensionFunc() {} + + fun test(f: Foo<*>) { + f.extensionFunc() + } + """.trimIndent() + ) as KtFile + + val extensionFunctionCall = psiFile.findDescendantOfType()!! + val uCallExpression = extensionFunctionCall.toUElementOfType()!! + + TestCase.assertNotNull(uCallExpression.receiverType) + TestCase.assertNotNull(uCallExpression.methodName) + } + fun testParameterInAnnotationClassFromFactory() { val detachedClass = KtPsiFactory(project).createClass("""