FE: Make synchronized suspend functions and lambdas error in 1.8
#KT-27333 Fixed
This commit is contained in:
+12
-6
@@ -35750,6 +35750,18 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspesionInDefaultValue.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("synchronizedOnSuspend.kt")
|
||||
public void testSynchronizedOnSuspend() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/synchronizedOnSuspend.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("synchronizedOnSuspendError.kt")
|
||||
public void testSynchronizedOnSuspendError() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/synchronizedOnSuspendError.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("tryCatchLambda.kt")
|
||||
public void testTryCatchLambda() throws Exception {
|
||||
@@ -37423,12 +37435,6 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
|
||||
public void testSynchronizedOnInline() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/inline/synchronizedOnInline.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("synchronizedOnSuspend.kt")
|
||||
public void testSynchronizedOnSuspend() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/inline/synchronizedOnSuspend.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+12
-6
@@ -35750,6 +35750,18 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/suspesionInDefaultValue.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("synchronizedOnSuspend.kt")
|
||||
public void testSynchronizedOnSuspend() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/synchronizedOnSuspend.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("synchronizedOnSuspendError.kt")
|
||||
public void testSynchronizedOnSuspendError() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/coroutines/synchronizedOnSuspendError.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("tryCatchLambda.kt")
|
||||
public void testTryCatchLambda() throws Exception {
|
||||
@@ -37423,12 +37435,6 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
|
||||
public void testSynchronizedOnInline() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/inline/synchronizedOnInline.kt");
|
||||
}
|
||||
|
||||
@Test
|
||||
@TestMetadata("synchronizedOnSuspend.kt")
|
||||
public void testSynchronizedOnSuspend() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithStdLib/inline/synchronizedOnSuspend.kt");
|
||||
}
|
||||
}
|
||||
|
||||
@Nested
|
||||
|
||||
+2
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.fir.checkers.generator.diagnostics
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.config.LanguageFeature.*
|
||||
import org.jetbrains.kotlin.fir.PrivateForInline
|
||||
import org.jetbrains.kotlin.fir.checkers.generator.diagnostics.model.DiagnosticList
|
||||
@@ -60,6 +61,7 @@ object JVM_DIAGNOSTICS_LIST : DiagnosticList("FirJvmErrors") {
|
||||
val SYNCHRONIZED_ON_ABSTRACT by error<KtAnnotationEntry>()
|
||||
val SYNCHRONIZED_IN_INTERFACE by error<KtAnnotationEntry>()
|
||||
val SYNCHRONIZED_ON_INLINE by warning<KtAnnotationEntry>()
|
||||
val SYNCHRONIZED_ON_SUSPEND by deprecationError<KtAnnotationEntry>(SynchronizedSuspendError)
|
||||
val OVERLOADS_WITHOUT_DEFAULT_ARGUMENTS by warning<KtAnnotationEntry>()
|
||||
val OVERLOADS_ABSTRACT by error<KtAnnotationEntry>()
|
||||
val OVERLOADS_INTERFACE by error<KtAnnotationEntry>()
|
||||
|
||||
+2
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.config.LanguageFeature.ProhibitConcurrentHashMapCont
|
||||
import org.jetbrains.kotlin.config.LanguageFeature.ProhibitJvmOverloadsOnConstructorsOfAnnotationClasses
|
||||
import org.jetbrains.kotlin.config.LanguageFeature.ProhibitSpreadOnSignaturePolymorphicCall
|
||||
import org.jetbrains.kotlin.config.LanguageFeature.RepeatableAnnotationContainerConstraints
|
||||
import org.jetbrains.kotlin.config.LanguageFeature.SynchronizedSuspendError
|
||||
import org.jetbrains.kotlin.diagnostics.*
|
||||
import org.jetbrains.kotlin.diagnostics.SourceElementPositioningStrategies
|
||||
import org.jetbrains.kotlin.diagnostics.rendering.RootDiagnosticRendererFactory
|
||||
@@ -58,6 +59,7 @@ object FirJvmErrors {
|
||||
val SYNCHRONIZED_ON_ABSTRACT by error0<KtAnnotationEntry>()
|
||||
val SYNCHRONIZED_IN_INTERFACE by error0<KtAnnotationEntry>()
|
||||
val SYNCHRONIZED_ON_INLINE by warning0<KtAnnotationEntry>()
|
||||
val SYNCHRONIZED_ON_SUSPEND by deprecationError0<KtAnnotationEntry>(SynchronizedSuspendError)
|
||||
val OVERLOADS_WITHOUT_DEFAULT_ARGUMENTS by warning0<KtAnnotationEntry>()
|
||||
val OVERLOADS_ABSTRACT by error0<KtAnnotationEntry>()
|
||||
val OVERLOADS_INTERFACE by error0<KtAnnotationEntry>()
|
||||
|
||||
+2
@@ -82,6 +82,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.SUSPENSION
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.SYNCHRONIZED_IN_INTERFACE
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.SYNCHRONIZED_ON_ABSTRACT
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.SYNCHRONIZED_ON_INLINE
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.SYNCHRONIZED_ON_SUSPEND
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.UPPER_BOUND_CANNOT_BE_ARRAY
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.VALUE_CLASS_WITHOUT_JVM_INLINE_ANNOTATION
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors.VOLATILE_ON_DELEGATE
|
||||
@@ -98,6 +99,7 @@ object FirJvmErrorsDefaultMessages : BaseDiagnosticRendererFactory() {
|
||||
map.put(VOLATILE_ON_DELEGATE, "'@Volatile' annotation cannot be used on delegated properties")
|
||||
map.put(SYNCHRONIZED_ON_ABSTRACT, "'@Synchronized' annotation cannot be used on abstract functions")
|
||||
map.put(SYNCHRONIZED_ON_INLINE, "'@Synchronized' annotation has no effect on inline functions")
|
||||
map.put(SYNCHRONIZED_ON_SUSPEND, "@Synchronized annotation is not applicable to suspend functions and lambdas")
|
||||
map.put(SYNCHRONIZED_IN_INTERFACE, "'@Synchronized' annotation cannot be used on interface members")
|
||||
map.put(OVERLOADS_WITHOUT_DEFAULT_ARGUMENTS, "'@JvmOverloads' annotation has no effect for methods without default arguments")
|
||||
map.put(OVERLOADS_ABSTRACT, "'@JvmOverloads' annotation cannot be used on abstract methods")
|
||||
|
||||
+11
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.jvm.checkers.declaration
|
||||
|
||||
import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.classKind
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
@@ -13,10 +14,14 @@ import org.jetbrains.kotlin.fir.analysis.checkers.getContainingClassSymbol
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.jvm.FirJvmErrors
|
||||
import org.jetbrains.kotlin.diagnostics.reportOn
|
||||
import org.jetbrains.kotlin.fir.declarations.FirAnonymousFunction
|
||||
import org.jetbrains.kotlin.fir.declarations.FirFunction
|
||||
import org.jetbrains.kotlin.fir.declarations.getAnnotationByClassId
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isAbstract
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isInline
|
||||
import org.jetbrains.kotlin.fir.declarations.utils.isSuspend
|
||||
import org.jetbrains.kotlin.fir.types.coneType
|
||||
import org.jetbrains.kotlin.fir.types.isSuspendFunctionType
|
||||
import org.jetbrains.kotlin.name.JvmNames.SYNCHRONIZED_ANNOTATION_CLASS_ID
|
||||
|
||||
object FirSynchronizedAnnotationChecker : FirFunctionChecker() {
|
||||
@@ -27,6 +32,12 @@ object FirSynchronizedAnnotationChecker : FirFunctionChecker() {
|
||||
reporter.reportOn(annotation.source, FirJvmErrors.SYNCHRONIZED_ON_INLINE, context)
|
||||
return
|
||||
}
|
||||
if (declaration.isSuspend ||
|
||||
(declaration as? FirAnonymousFunction)?.typeRef?.coneType?.isSuspendFunctionType(context.session) == true
|
||||
) {
|
||||
reporter.reportOn(annotation.source, FirJvmErrors.SYNCHRONIZED_ON_SUSPEND, context)
|
||||
return
|
||||
}
|
||||
|
||||
val containingClass = declaration.getContainingClassSymbol(context.session) ?: return
|
||||
if (containingClass.classKind == ClassKind.INTERFACE) {
|
||||
|
||||
Reference in New Issue
Block a user