From 74043089ab6cbd7bffe735bbd94cf45ba2af73ba Mon Sep 17 00:00:00 2001 From: Nikolay Krasko Date: Mon, 11 Sep 2017 12:08:00 +0300 Subject: [PATCH] Generate modifier list stub under nullable type for suspend functions (KT-20185) Otherwise there's a PSI and Stub mismatch error produced. #KT-20185 Fixed --- .../kotlin/psi/stubs/KotlinStubVersions.kt | 2 +- .../stubBuilder/TypeClsStubBuilder.kt | 16 ++- .../SuspendLambda/SuspendLambda.kt | 16 ++- .../SuspendLambda/SuspendLambda.txt | 115 +++++++++++++++++- 4 files changed, 140 insertions(+), 9 deletions(-) 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 94900303651..891ee7a15cf 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 = 61 + private const val BINARY_STUB_VERSION = 62 // 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/TypeClsStubBuilder.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/TypeClsStubBuilder.kt index b38707db7b4..6ec8f50b88c 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/TypeClsStubBuilder.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/stubBuilder/TypeClsStubBuilder.kt @@ -95,10 +95,20 @@ class TypeClsStubBuilder(private val c: ClsStubBuilderContext) { val (extensionAnnotations, notExtensionAnnotations) = annotations.partition { it.classId.asSingleFqName() == KotlinBuiltIns.FQ_NAMES.extensionFunctionType } - createTypeAnnotationStubs(parent, type, notExtensionAnnotations) - val isExtension = extensionAnnotations.isNotEmpty() - createFunctionTypeStub(nullableTypeParent(parent, type), type, isExtension, Flags.SUSPEND_TYPE.get(type.flags)) + val isSuspend = Flags.SUSPEND_TYPE.get(type.flags) + + val nullableWrapper = if (isSuspend) { + val wrapper = nullableTypeParent(parent, type) + createTypeAnnotationStubs(wrapper, type, notExtensionAnnotations) + wrapper + } + else { + createTypeAnnotationStubs(parent, type, notExtensionAnnotations) + nullableTypeParent(parent, type) + } + + createFunctionTypeStub(nullableWrapper, type, isExtension, isSuspend) return } diff --git a/idea/testData/decompiler/stubBuilder/SuspendLambda/SuspendLambda.kt b/idea/testData/decompiler/stubBuilder/SuspendLambda/SuspendLambda.kt index 07ebe4fa4a0..7a8ef91003a 100644 --- a/idea/testData/decompiler/stubBuilder/SuspendLambda/SuspendLambda.kt +++ b/idea/testData/decompiler/stubBuilder/SuspendLambda/SuspendLambda.kt @@ -1,18 +1,28 @@ package test class SuspendLambda { - fun (suspend () -> T).createCoroutine(completion: Continuation) {} + fun (suspend () -> T).createCoroutine1(completion: Continuation) {} - fun (suspend R.() -> T).createCoroutine(receiver: R, completion: Continuation) {} + fun (suspend R.() -> T).createCoroutine2(receiver: R, completion: Continuation) {} fun (suspend @receiver:A R.() -> T).createCoroutineAnother() {} fun testCoroutine(f: suspend (Int) -> T?) {} fun testCoroutineWithAnnotation(f: suspend (Int) -> @A T?) {} + + var nullableSuspend: (suspend (P) -> Unit)? = null + var nullableSuspendWithReceiver: (suspend RS.(P) -> Unit)? = null + var nullableSuspendWithNullableParameter: (suspend (P?) -> Unit)? = null + var nullableSuspendWithNullableReceiver: (suspend RS?.(P) -> Unit)? = null + + var nullableSuspendWithAnnotation: (@A() suspend (P) -> Unit)? = null } -@Target(AnnotationTarget.TYPE, AnnotationTarget.TYPE_PARAMETER, AnnotationTarget.VALUE_PARAMETER) +interface P +interface RS + +@Target(AnnotationTarget.TYPE, AnnotationTarget.VALUE_PARAMETER) annotation class A class Continuation {} \ No newline at end of file diff --git a/idea/testData/decompiler/stubBuilder/SuspendLambda/SuspendLambda.txt b/idea/testData/decompiler/stubBuilder/SuspendLambda/SuspendLambda.txt index 0ce0dbb9b8c..10c0046b0bf 100644 --- a/idea/testData/decompiler/stubBuilder/SuspendLambda/SuspendLambda.txt +++ b/idea/testData/decompiler/stubBuilder/SuspendLambda/SuspendLambda.txt @@ -8,6 +8,117 @@ PsiJetFileStubImpl[package=test] MODIFIER_LIST[public] VALUE_PARAMETER_LIST CLASS_BODY + PROPERTY[fqName=test.SuspendLambda.nullableSuspend, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=true, name=nullableSuspend] + MODIFIER_LIST[public final] + TYPE_REFERENCE + NULLABLE_TYPE + MODIFIER_LIST[suspend] + FUNCTION_TYPE + VALUE_PARAMETER_LIST + VALUE_PARAMETER[fqName=null, hasDefaultValue=false, hasValOrVar=false, isMutable=false, name=null] + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=test] + REFERENCE_EXPRESSION[referencedName=P] + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=kotlin] + REFERENCE_EXPRESSION[referencedName=Unit] + PROPERTY[fqName=test.SuspendLambda.nullableSuspendWithAnnotation, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=true, name=nullableSuspendWithAnnotation] + MODIFIER_LIST[public final] + TYPE_REFERENCE + NULLABLE_TYPE + MODIFIER_LIST[suspend] + ANNOTATION_ENTRY[hasValueArguments=false, shortName=A] + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=test] + REFERENCE_EXPRESSION[referencedName=A] + FUNCTION_TYPE + VALUE_PARAMETER_LIST + VALUE_PARAMETER[fqName=null, hasDefaultValue=false, hasValOrVar=false, isMutable=false, name=null] + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=test] + REFERENCE_EXPRESSION[referencedName=P] + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=kotlin] + REFERENCE_EXPRESSION[referencedName=Unit] + PROPERTY[fqName=test.SuspendLambda.nullableSuspendWithNullableParameter, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=true, name=nullableSuspendWithNullableParameter] + MODIFIER_LIST[public final] + TYPE_REFERENCE + NULLABLE_TYPE + MODIFIER_LIST[suspend] + FUNCTION_TYPE + VALUE_PARAMETER_LIST + VALUE_PARAMETER[fqName=null, hasDefaultValue=false, hasValOrVar=false, isMutable=false, name=null] + TYPE_REFERENCE + NULLABLE_TYPE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=test] + REFERENCE_EXPRESSION[referencedName=P] + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=kotlin] + REFERENCE_EXPRESSION[referencedName=Unit] + PROPERTY[fqName=test.SuspendLambda.nullableSuspendWithNullableReceiver, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=true, name=nullableSuspendWithNullableReceiver] + MODIFIER_LIST[public final] + TYPE_REFERENCE + NULLABLE_TYPE + MODIFIER_LIST[suspend] + FUNCTION_TYPE + FUNCTION_TYPE_RECEIVER + TYPE_REFERENCE + NULLABLE_TYPE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=test] + REFERENCE_EXPRESSION[referencedName=RS] + VALUE_PARAMETER_LIST + VALUE_PARAMETER[fqName=null, hasDefaultValue=false, hasValOrVar=false, isMutable=false, name=null] + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=test] + REFERENCE_EXPRESSION[referencedName=P] + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=kotlin] + REFERENCE_EXPRESSION[referencedName=Unit] + PROPERTY[fqName=test.SuspendLambda.nullableSuspendWithReceiver, hasDelegate=false, hasDelegateExpression=false, hasInitializer=false, hasReturnTypeRef=true, isExtension=false, isTopLevel=false, isVar=true, name=nullableSuspendWithReceiver] + MODIFIER_LIST[public final] + TYPE_REFERENCE + NULLABLE_TYPE + MODIFIER_LIST[suspend] + FUNCTION_TYPE + FUNCTION_TYPE_RECEIVER + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=test] + REFERENCE_EXPRESSION[referencedName=RS] + VALUE_PARAMETER_LIST + VALUE_PARAMETER[fqName=null, hasDefaultValue=false, hasValOrVar=false, isMutable=false, name=null] + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=test] + REFERENCE_EXPRESSION[referencedName=P] + TYPE_REFERENCE + USER_TYPE + USER_TYPE + REFERENCE_EXPRESSION[referencedName=kotlin] + REFERENCE_EXPRESSION[referencedName=Unit] FUN[fqName=test.SuspendLambda.testCoroutine, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=true, isExtension=false, isTopLevel=false, name=testCoroutine] MODIFIER_LIST[public final] TYPE_PARAMETER_LIST @@ -66,7 +177,7 @@ PsiJetFileStubImpl[package=test] USER_TYPE REFERENCE_EXPRESSION[referencedName=kotlin] REFERENCE_EXPRESSION[referencedName=Unit] - FUN[fqName=test.SuspendLambda.createCoroutine, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=true, isExtension=true, isTopLevel=false, name=createCoroutine] + FUN[fqName=test.SuspendLambda.createCoroutine1, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=true, isExtension=true, isTopLevel=false, name=createCoroutine1] MODIFIER_LIST[public final] TYPE_PARAMETER_LIST TYPE_PARAMETER[fqName=null, isInVariance=false, isOutVariance=false, name=T] @@ -94,7 +205,7 @@ PsiJetFileStubImpl[package=test] USER_TYPE REFERENCE_EXPRESSION[referencedName=kotlin] REFERENCE_EXPRESSION[referencedName=Unit] - FUN[fqName=test.SuspendLambda.createCoroutine, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=true, isExtension=true, isTopLevel=false, name=createCoroutine] + FUN[fqName=test.SuspendLambda.createCoroutine2, hasBlockBody=true, hasBody=true, hasTypeParameterListBeforeFunctionName=true, isExtension=true, isTopLevel=false, name=createCoroutine2] MODIFIER_LIST[public final] TYPE_PARAMETER_LIST TYPE_PARAMETER[fqName=null, isInVariance=false, isOutVariance=false, name=R]