From 6bf987e772cd998ded54aaa66a657b724104d2be Mon Sep 17 00:00:00 2001 From: Brian Norman Date: Wed, 6 Mar 2024 11:04:30 -0600 Subject: [PATCH] [AllOpen] Do not open members of non-class type classes The logic of the AllOpen compiler plugin for opening classes and opening declarations of classes does not match. This leads to declarations being open when the containing class is not open. There is a warning reported, for exactly this situation. However, creating meta-annotations of AllOpen annotation is quite common in certain ecosystems. In particular, Spring. This can lead to a warning if the meta-annotation has properties. Align the class kind check for members, so they are not opened if the containing class cannot be opened. ^KT-63507 Fixed --- .../kotlin/allopen/fir/FirAllOpenStatusTransformer.kt | 2 +- .../testData/diagnostics/allOpenOnAnnotation.fir.kt | 9 --------- .../allopen/testData/diagnostics/allOpenOnAnnotation.kt | 1 + plugins/allopen/testData/diagnostics/kt54260.fir.kt | 9 --------- plugins/allopen/testData/diagnostics/kt54260.kt | 1 + 5 files changed, 3 insertions(+), 19 deletions(-) delete mode 100644 plugins/allopen/testData/diagnostics/allOpenOnAnnotation.fir.kt delete mode 100644 plugins/allopen/testData/diagnostics/kt54260.fir.kt diff --git a/plugins/allopen/allopen.k2/src/org/jetbrains/kotlin/allopen/fir/FirAllOpenStatusTransformer.kt b/plugins/allopen/allopen.k2/src/org/jetbrains/kotlin/allopen/fir/FirAllOpenStatusTransformer.kt index c90e8151ffe..8a308c55139 100644 --- a/plugins/allopen/allopen.k2/src/org/jetbrains/kotlin/allopen/fir/FirAllOpenStatusTransformer.kt +++ b/plugins/allopen/allopen.k2/src/org/jetbrains/kotlin/allopen/fir/FirAllOpenStatusTransformer.kt @@ -30,7 +30,7 @@ class FirAllOpenStatusTransformer(session: FirSession) : FirStatusTransformerExt if (parentClassId.isLocal) return false val parentClassSymbol = session.symbolProvider.getClassLikeSymbolByClassId(parentClassId) as? FirRegularClassSymbol ?: return false - session.allOpenPredicateMatcher.isAnnotated(parentClassSymbol) + parentClassSymbol.classKind == ClassKind.CLASS && session.allOpenPredicateMatcher.isAnnotated(parentClassSymbol) } else -> false } diff --git a/plugins/allopen/testData/diagnostics/allOpenOnAnnotation.fir.kt b/plugins/allopen/testData/diagnostics/allOpenOnAnnotation.fir.kt deleted file mode 100644 index 863810dfd08..00000000000 --- a/plugins/allopen/testData/diagnostics/allOpenOnAnnotation.fir.kt +++ /dev/null @@ -1,9 +0,0 @@ -// WITH_STDLIB -// ISSUE: KT-63507 - -annotation class AllOpen - -@AllOpen -annotation class SubComponent( - val scope: String -) diff --git a/plugins/allopen/testData/diagnostics/allOpenOnAnnotation.kt b/plugins/allopen/testData/diagnostics/allOpenOnAnnotation.kt index 3e48ce69633..36e54e846dd 100644 --- a/plugins/allopen/testData/diagnostics/allOpenOnAnnotation.kt +++ b/plugins/allopen/testData/diagnostics/allOpenOnAnnotation.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // WITH_STDLIB // ISSUE: KT-63507 diff --git a/plugins/allopen/testData/diagnostics/kt54260.fir.kt b/plugins/allopen/testData/diagnostics/kt54260.fir.kt deleted file mode 100644 index 36a668f0233..00000000000 --- a/plugins/allopen/testData/diagnostics/kt54260.fir.kt +++ /dev/null @@ -1,9 +0,0 @@ -// WITH_STDLIB - -annotation class AllOpen - -@AllOpen -annotation class ConsoleCommands( - val value: String = "", - val scope: String -) diff --git a/plugins/allopen/testData/diagnostics/kt54260.kt b/plugins/allopen/testData/diagnostics/kt54260.kt index f24494383b2..5886b799d5c 100644 --- a/plugins/allopen/testData/diagnostics/kt54260.kt +++ b/plugins/allopen/testData/diagnostics/kt54260.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // WITH_STDLIB annotation class AllOpen