Report warning on @Synchronized on inline methods
Until KT-27310 is supported, we warn users that this has no effect. #KT-29884 Fixed
This commit is contained in:
+27
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.resolve.jvm.checkers
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
|
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||||
|
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||||
|
import org.jetbrains.kotlin.resolve.checkers.DeclarationChecker
|
||||||
|
import org.jetbrains.kotlin.resolve.checkers.DeclarationCheckerContext
|
||||||
|
import org.jetbrains.kotlin.resolve.jvm.annotations.findSynchronizedAnnotation
|
||||||
|
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||||
|
|
||||||
|
object SynchronizedOnInlineMethodChecker : DeclarationChecker {
|
||||||
|
override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) {
|
||||||
|
if (descriptor is FunctionDescriptor && descriptor.isInline) {
|
||||||
|
val annotation = descriptor.findSynchronizedAnnotation()
|
||||||
|
if (annotation != null) {
|
||||||
|
val reportOn = DescriptorToSourceUtils.getSourceFromAnnotation(annotation) ?: declaration
|
||||||
|
context.trace.report(ErrorsJvm.SYNCHRONIZED_ON_INLINE.on(reportOn))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+1
@@ -57,6 +57,7 @@ public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension {
|
|||||||
MAP.put(VOLATILE_ON_VALUE, "'@Volatile' annotation cannot be used on immutable properties");
|
MAP.put(VOLATILE_ON_VALUE, "'@Volatile' annotation cannot be used on immutable properties");
|
||||||
MAP.put(VOLATILE_ON_DELEGATE, "'@Volatile' annotation cannot be used on delegated properties");
|
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_ABSTRACT, "'@Synchronized' annotation cannot be used on abstract functions");
|
||||||
|
MAP.put(SYNCHRONIZED_ON_INLINE, "'@Synchronized' annotation has no effect on inline functions");
|
||||||
MAP.put(EXTERNAL_DECLARATION_CANNOT_BE_ABSTRACT, "External declaration can not be abstract");
|
MAP.put(EXTERNAL_DECLARATION_CANNOT_BE_ABSTRACT, "External declaration can not be abstract");
|
||||||
MAP.put(EXTERNAL_DECLARATION_CANNOT_HAVE_BODY, "External declaration can not have a body");
|
MAP.put(EXTERNAL_DECLARATION_CANNOT_HAVE_BODY, "External declaration can not have a body");
|
||||||
MAP.put(EXTERNAL_DECLARATION_IN_INTERFACE, "Members of interfaces can not be external");
|
MAP.put(EXTERNAL_DECLARATION_IN_INTERFACE, "Members of interfaces can not be external");
|
||||||
|
|||||||
@@ -48,6 +48,7 @@ public interface ErrorsJvm {
|
|||||||
DiagnosticFactory0<KtAnnotationEntry> VOLATILE_ON_VALUE = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<KtAnnotationEntry> VOLATILE_ON_VALUE = DiagnosticFactory0.create(ERROR);
|
||||||
DiagnosticFactory0<KtAnnotationEntry> VOLATILE_ON_DELEGATE = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<KtAnnotationEntry> VOLATILE_ON_DELEGATE = DiagnosticFactory0.create(ERROR);
|
||||||
DiagnosticFactory0<KtAnnotationEntry> SYNCHRONIZED_ON_ABSTRACT = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<KtAnnotationEntry> SYNCHRONIZED_ON_ABSTRACT = DiagnosticFactory0.create(ERROR);
|
||||||
|
DiagnosticFactory0<KtElement> SYNCHRONIZED_ON_INLINE = DiagnosticFactory0.create(WARNING);
|
||||||
|
|
||||||
DiagnosticFactory0<KtAnnotationEntry> OVERLOADS_WITHOUT_DEFAULT_ARGUMENTS = DiagnosticFactory0.create(WARNING);
|
DiagnosticFactory0<KtAnnotationEntry> OVERLOADS_WITHOUT_DEFAULT_ARGUMENTS = DiagnosticFactory0.create(WARNING);
|
||||||
DiagnosticFactory0<KtAnnotationEntry> OVERLOADS_ABSTRACT = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<KtAnnotationEntry> OVERLOADS_ABSTRACT = DiagnosticFactory0.create(ERROR);
|
||||||
|
|||||||
+2
-1
@@ -37,7 +37,8 @@ object JvmPlatformConfigurator : PlatformConfiguratorBase(
|
|||||||
ExpectedActualDeclarationChecker(listOf(JavaActualAnnotationArgumentExtractor())),
|
ExpectedActualDeclarationChecker(listOf(JavaActualAnnotationArgumentExtractor())),
|
||||||
JvmAnnotationsTargetNonExistentAccessorChecker(),
|
JvmAnnotationsTargetNonExistentAccessorChecker(),
|
||||||
BadInheritedJavaSignaturesChecker,
|
BadInheritedJavaSignaturesChecker,
|
||||||
JvmMultifileClassStateChecker
|
JvmMultifileClassStateChecker,
|
||||||
|
SynchronizedOnInlineMethodChecker
|
||||||
),
|
),
|
||||||
|
|
||||||
additionalCallCheckers = listOf(
|
additionalCallCheckers = listOf(
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||||
|
|
||||||
|
<!SYNCHRONIZED_ON_INLINE!>@Synchronized<!>
|
||||||
|
inline fun foo(f: () -> Unit): Unit = f()
|
||||||
|
|
||||||
|
var bar: String
|
||||||
|
<!SYNCHRONIZED_ON_INLINE!>@Synchronized<!>
|
||||||
|
inline get() = ""
|
||||||
|
<!SYNCHRONIZED_ON_INLINE!>@Synchronized<!>
|
||||||
|
inline set(value) {}
|
||||||
|
|
||||||
|
inline var baz: String
|
||||||
|
<!SYNCHRONIZED_ON_INLINE!>@Synchronized<!>
|
||||||
|
get() = ""
|
||||||
|
<!SYNCHRONIZED_ON_INLINE!>@Synchronized<!>
|
||||||
|
set(value) {}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
@get:kotlin.jvm.Synchronized @set:kotlin.jvm.Synchronized public var bar: kotlin.String
|
||||||
|
@get:kotlin.jvm.Synchronized @set:kotlin.jvm.Synchronized public var baz: kotlin.String
|
||||||
|
@kotlin.jvm.Synchronized public inline fun foo(/*0*/ f: () -> kotlin.Unit): kotlin.Unit
|
||||||
+5
@@ -2736,6 +2736,11 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
|
|||||||
public void testInlineOnlySuppressesNothingToInline() throws Exception {
|
public void testInlineOnlySuppressesNothingToInline() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/inline/inlineOnlySuppressesNothingToInline.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/inline/inlineOnlySuppressesNothingToInline.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("synchronizedOnInline.kt")
|
||||||
|
public void testSynchronizedOnInline() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/inline/synchronizedOnInline.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/java")
|
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/java")
|
||||||
|
|||||||
compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java
Generated
+5
@@ -2736,6 +2736,11 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno
|
|||||||
public void testInlineOnlySuppressesNothingToInline() throws Exception {
|
public void testInlineOnlySuppressesNothingToInline() throws Exception {
|
||||||
runTest("compiler/testData/diagnostics/testsWithStdLib/inline/inlineOnlySuppressesNothingToInline.kt");
|
runTest("compiler/testData/diagnostics/testsWithStdLib/inline/inlineOnlySuppressesNothingToInline.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("synchronizedOnInline.kt")
|
||||||
|
public void testSynchronizedOnInline() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/inline/synchronizedOnInline.kt");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/java")
|
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/java")
|
||||||
|
|||||||
Reference in New Issue
Block a user