From 16ca8ddbbd6f3e6863ce08d24101800e891afcc4 Mon Sep 17 00:00:00 2001 From: "Denis.Zharkov" Date: Wed, 7 Apr 2021 19:02:51 +0300 Subject: [PATCH] Do not parse !! as part of annotation type ^KT-26245 Related --- .../kotlin/parsing/KotlinParsing.java | 8 +-- .../testData/psi/DefinitelyNotNullType.kt | 4 ++ .../testData/psi/DefinitelyNotNullType.txt | 54 ++++++++++++++++++- 3 files changed, 61 insertions(+), 5 deletions(-) diff --git a/compiler/psi/src/org/jetbrains/kotlin/parsing/KotlinParsing.java b/compiler/psi/src/org/jetbrains/kotlin/parsing/KotlinParsing.java index 57a44005ade..7e05974e7e8 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/parsing/KotlinParsing.java +++ b/compiler/psi/src/org/jetbrains/kotlin/parsing/KotlinParsing.java @@ -833,7 +833,7 @@ public class KotlinParsing extends AbstractKotlinParsing { PsiBuilder.Marker reference = mark(); PsiBuilder.Marker typeReference = mark(); - parseUserType(); + parseUserType(/* forAnnotation */ true); typeReference.done(TYPE_REFERENCE); reference.done(CONSTRUCTOR_CALLEE); @@ -2078,7 +2078,7 @@ public class KotlinParsing extends AbstractKotlinParsing { dynamicType.done(DYNAMIC_TYPE); } else if (at(IDENTIFIER) || at(PACKAGE_KEYWORD) || atParenthesizedMutableForPlatformTypes(0)) { - parseUserType(); + parseUserType(/* forAnnotation */ false); } else if (at(LPAR)) { PsiBuilder.Marker functionOrParenthesizedType = mark(); @@ -2175,7 +2175,7 @@ public class KotlinParsing extends AbstractKotlinParsing { * - (Mutable)List! * - Array<(out) Foo>! */ - private void parseUserType() { + private void parseUserType(boolean forAnnotation) { PsiBuilder.Marker userType = mark(); if (at(PACKAGE_KEYWORD)) { @@ -2221,7 +2221,7 @@ public class KotlinParsing extends AbstractKotlinParsing { userType.done(USER_TYPE); - if (at(EXCLEXCL)) { + if (!forAnnotation && at(EXCLEXCL)) { PsiBuilder.Marker definitelyNotNull = userType.precede(); advance(); // !! definitelyNotNull.done(DEFINITELY_NOT_NULL_TYPE); diff --git a/compiler/testData/psi/DefinitelyNotNullType.kt b/compiler/testData/psi/DefinitelyNotNullType.kt index 754b38edaf1..e160b28217e 100644 --- a/compiler/testData/psi/DefinitelyNotNullType.kt +++ b/compiler/testData/psi/DefinitelyNotNullType.kt @@ -3,3 +3,7 @@ fun foo1(x: T!!, y: List, z: T!!.(T!!) -> T!!): T!! {} // should be prohibited on type-resolution level fun foo2(x: T!!?, y: List, z: T!!?.(T!!?) -> T!!?, w: String!!): T!! {} + +fun foo3() { + if (@RetentionSourceAndTargetExpression !!(x == y)) {} +} diff --git a/compiler/testData/psi/DefinitelyNotNullType.txt b/compiler/testData/psi/DefinitelyNotNullType.txt index e80c6ad4aae..c5a260822b9 100644 --- a/compiler/testData/psi/DefinitelyNotNullType.txt +++ b/compiler/testData/psi/DefinitelyNotNullType.txt @@ -207,4 +207,56 @@ KtFile: DefinitelyNotNullType.kt PsiWhiteSpace(' ') BLOCK PsiElement(LBRACE)('{') - PsiElement(RBRACE)('}') \ No newline at end of file + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n\n') + FUN + PsiElement(fun)('fun') + PsiWhiteSpace(' ') + PsiElement(IDENTIFIER)('foo3') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + BLOCK + PsiElement(LBRACE)('{') + PsiWhiteSpace('\n ') + IF + PsiElement(if)('if') + PsiWhiteSpace(' ') + PsiElement(LPAR)('(') + CONDITION + ANNOTATED_EXPRESSION + ANNOTATION_ENTRY + PsiElement(AT)('@') + CONSTRUCTOR_CALLEE + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('RetentionSourceAndTargetExpression') + PsiWhiteSpace(' ') + PREFIX_EXPRESSION + OPERATION_REFERENCE + PsiElement(EXCL)('!') + PREFIX_EXPRESSION + OPERATION_REFERENCE + PsiElement(EXCL)('!') + PARENTHESIZED + PsiElement(LPAR)('(') + BINARY_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('x') + PsiWhiteSpace(' ') + OPERATION_REFERENCE + PsiElement(EQEQ)('==') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('y') + PsiElement(RPAR)(')') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + THEN + BLOCK + PsiElement(LBRACE)('{') + PsiElement(RBRACE)('}') + PsiWhiteSpace('\n') + PsiElement(RBRACE)('}')