From c076ad5a8da8ac72e7aaed44b729490a5fb11039 Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Fri, 16 Dec 2016 19:28:06 +0300 Subject: [PATCH] Don't assign type parameters from original proto if type is substituted with Any (KT-15128) #KT-15128 Fixed --- .../kotlin/psi/stubs/KotlinStubVersions.kt | 2 +- .../decompiler/stubBuilder/clsStubBuilding.kt | 10 ++-- .../AnonymousReturnWithGenericType.kt | 9 ++++ .../AnonymousReturnWithGenericType.txt | 47 +++++++++++++++++++ .../ClsStubBuilderTestGenerated.java | 6 +++ 5 files changed, 70 insertions(+), 4 deletions(-) create mode 100644 idea/testData/decompiler/stubBuilder/AnonymousReturnWithGenericType/AnonymousReturnWithGenericType.kt create mode 100644 idea/testData/decompiler/stubBuilder/AnonymousReturnWithGenericType/AnonymousReturnWithGenericType.txt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt index f6a591af332..a4e6dbf9008 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/psi/stubs/KotlinStubVersions.kt @@ -28,7 +28,7 @@ object KotlinStubVersions { // Binary stub version should be increased if stub format (org.jetbrains.kotlin.psi.stubs.impl) is changed // or changes are made to the core stub building code (org.jetbrains.kotlin.idea.decompiler.stubBuilder). // Increasing this version will lead to reindexing of all binary files that are potentially kotlin binaries (including all class files). - private const val BINARY_STUB_VERSION = 56 + private const val BINARY_STUB_VERSION = 57 // Classfile stub version should be increased if changes are made to classfile stub building subsystem (org.jetbrains.kotlin.idea.decompiler.classFile) // Increasing this version will lead to reindexing of all classfiles. diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/clsStubBuilding.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/clsStubBuilding.kt index 9cd67cd3e83..47e49ad7533 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/clsStubBuilding.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/clsStubBuilding.kt @@ -141,10 +141,12 @@ fun createStubForPackageName(packageDirectiveStub: KotlinPlaceHolderStubImpl, - onUserTypeLevel: (KotlinUserTypeStub, Int) -> Unit = { x, y -> } + bindTypeArguments: (KotlinUserTypeStub, Int) -> Unit = { x, y -> } ): KotlinUserTypeStub { + val substituteWithAny = typeClassId.isLocal + val fqName = - if (typeClassId.isLocal) KotlinBuiltIns.FQ_NAMES.any + if (substituteWithAny) KotlinBuiltIns.FQ_NAMES.any else typeClassId.asSingleFqName().toUnsafe() val segments = fqName.pathSegments().asReversed() assert(segments.isNotEmpty()) @@ -156,7 +158,9 @@ fun createStubForTypeName( recCreateStubForType(userTypeStub, level + 1) } KotlinNameReferenceExpressionStubImpl(userTypeStub, lastSegment.ref()) - onUserTypeLevel(userTypeStub, level) + if (!substituteWithAny) { + bindTypeArguments(userTypeStub, level) + } return userTypeStub } diff --git a/idea/testData/decompiler/stubBuilder/AnonymousReturnWithGenericType/AnonymousReturnWithGenericType.kt b/idea/testData/decompiler/stubBuilder/AnonymousReturnWithGenericType/AnonymousReturnWithGenericType.kt new file mode 100644 index 00000000000..cf8ddcd0256 --- /dev/null +++ b/idea/testData/decompiler/stubBuilder/AnonymousReturnWithGenericType/AnonymousReturnWithGenericType.kt @@ -0,0 +1,9 @@ +interface Foo + +class AnonymousReturnWithGenericType { + val v1 = object : Foo {} + fun f1() = object : Foo {} + + private val v2 = object : Foo {} + private fun f2() = object : Foo {} +} \ No newline at end of file diff --git a/idea/testData/decompiler/stubBuilder/AnonymousReturnWithGenericType/AnonymousReturnWithGenericType.txt b/idea/testData/decompiler/stubBuilder/AnonymousReturnWithGenericType/AnonymousReturnWithGenericType.txt new file mode 100644 index 00000000000..b42d1310f3e --- /dev/null +++ b/idea/testData/decompiler/stubBuilder/AnonymousReturnWithGenericType/AnonymousReturnWithGenericType.txt @@ -0,0 +1,47 @@ +PsiJetFileStubImpl[package=] + PACKAGE_DIRECTIVE + IMPORT_LIST + CLASS[fqName=AnonymousReturnWithGenericType, isEnumEntry=false, isInterface=false, isLocal=false, isTopLevel=true, name=AnonymousReturnWithGenericType, superNames=[]] + MODIFIER_LIST[public final] + TYPE_PARAMETER_LIST + TYPE_PARAMETER[fqName=null, isInVariance=false, isOutVariance=false, name=T] + PRIMARY_CONSTRUCTOR + MODIFIER_LIST[public] + VALUE_PARAMETER_LIST + CLASS_BODY + PROPERTY[fqName=AnonymousReturnWithGenericType.v1, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=false, name=v1] + MODIFIER_LIST[public final] + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=Foo] + TYPE_ARGUMENT_LIST + TYPE_PROJECTION[projectionKind=NONE] + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=T] + PROPERTY[fqName=AnonymousReturnWithGenericType.v2, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=false, name=v2] + MODIFIER_LIST[private final] + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=kotlin] + REFERENCE_EXPRESSION[referencedName=Any] + FUN[fqName=AnonymousReturnWithGenericType.f1, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=false, name=f1] + MODIFIER_LIST[public final] + VALUE_PARAMETER_LIST + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=Foo] + TYPE_ARGUMENT_LIST + TYPE_PROJECTION[projectionKind=NONE] + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=T] + FUN[fqName=AnonymousReturnWithGenericType.f2, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=false, isExtension=false, isTopLevel=false, name=f2] + MODIFIER_LIST[private final] + VALUE_PARAMETER_LIST + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=kotlin] + REFERENCE_EXPRESSION[referencedName=Any] diff --git a/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/ClsStubBuilderTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/ClsStubBuilderTestGenerated.java index 39e7ed558e7..ed066da0901 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/ClsStubBuilderTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/decompiler/stubBuilder/ClsStubBuilderTestGenerated.java @@ -60,6 +60,12 @@ public class ClsStubBuilderTestGenerated extends AbstractClsStubBuilderTest { doTest(fileName); } + @TestMetadata("AnonymousReturnWithGenericType") + public void testAnonymousReturnWithGenericType() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/stubBuilder/AnonymousReturnWithGenericType/"); + doTest(fileName); + } + @TestMetadata("ClassMembers") public void testClassMembers() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("idea/testData/decompiler/stubBuilder/ClassMembers/");