From e75f89a4f74101b9ca697a98914613d2ffd6f2c2 Mon Sep 17 00:00:00 2001 From: "Victoria.Petrakovich" Date: Thu, 3 Oct 2024 17:21:42 +0200 Subject: [PATCH] [kotlin] Add explanation why parenthesis is added after annotated expression KTIJ-28468 kotlinOptions to compilerOptions inspection (kts only) GitOrigin-RevId: d2c83f809766e67aaf57b98de27cb7c5dcf1b143 --- .../freeCompilerArgsWithSupress.gradle.kts | 13 ++++++++----- .../freeCompilerArgsWithSupress.gradle.kts.after | 11 +++++++---- 2 files changed, 15 insertions(+), 9 deletions(-) diff --git a/plugins/kotlin/code-insight/inspections-k2/tests/testData/inspectionsLocal/kotlinOptionsToCompilerOptions/freeCompilerArgsWithSupress.gradle.kts b/plugins/kotlin/code-insight/inspections-k2/tests/testData/inspectionsLocal/kotlinOptionsToCompilerOptions/freeCompilerArgsWithSupress.gradle.kts index d2dcaf6ad5fa..2280eeb6f52b 100644 --- a/plugins/kotlin/code-insight/inspections-k2/tests/testData/inspectionsLocal/kotlinOptionsToCompilerOptions/freeCompilerArgsWithSupress.gradle.kts +++ b/plugins/kotlin/code-insight/inspections-k2/tests/testData/inspectionsLocal/kotlinOptionsToCompilerOptions/freeCompilerArgsWithSupress.gradle.kts @@ -20,8 +20,11 @@ tasks.test { useJUnitPlatform() } -val compileKotlin: KotlinCompile by tasks -kotlinOptions { - @Suppress("SuspiciousCollectionReassignment") - freeCompilerArgs += listOf("-Xopt-in=kotlin.RequiresOptIn") -} +tasks.withType { + kotlinOptions { + @Suppress("SuspiciousCollectionReassignment") + freeCompilerArgs += listOf("-Xopt-in=kotlin.RequiresOptIn") + // KtExpressionImpl performs replaceExpression() and there calls KtPsiUtil.areParenthesesNecessary(). Inside, innerPriority is calculated + // for DOT_QUALIFIED_EXPRESSION and it's 14, parentPriority is calculated for ANNOTATED_EXPRESSION is 15, and that's why () are added + } +} \ No newline at end of file diff --git a/plugins/kotlin/code-insight/inspections-k2/tests/testData/inspectionsLocal/kotlinOptionsToCompilerOptions/freeCompilerArgsWithSupress.gradle.kts.after b/plugins/kotlin/code-insight/inspections-k2/tests/testData/inspectionsLocal/kotlinOptionsToCompilerOptions/freeCompilerArgsWithSupress.gradle.kts.after index 41e85a87c9e6..64d1486c03a9 100644 --- a/plugins/kotlin/code-insight/inspections-k2/tests/testData/inspectionsLocal/kotlinOptionsToCompilerOptions/freeCompilerArgsWithSupress.gradle.kts.after +++ b/plugins/kotlin/code-insight/inspections-k2/tests/testData/inspectionsLocal/kotlinOptionsToCompilerOptions/freeCompilerArgsWithSupress.gradle.kts.after @@ -20,8 +20,11 @@ tasks.test { useJUnitPlatform() } -val compileKotlin: KotlinCompile by tasks -compilerOptions { - @Suppress("SuspiciousCollectionReassignment") - (freeCompilerArgs.addAll(listOf("-Xopt-in=kotlin.RequiresOptIn"))) +tasks.withType { + compilerOptions { + @Suppress("SuspiciousCollectionReassignment") + (freeCompilerArgs.addAll(listOf("-Xopt-in=kotlin.RequiresOptIn"))) + // KtExpressionImpl performs replaceExpression() and there calls KtPsiUtil.areParenthesesNecessary(). Inside, innerPriority is calculated + // for DOT_QUALIFIED_EXPRESSION and it's 14, parentPriority is calculated for ANNOTATED_EXPRESSION is 15, and that's why () are added + } }