Report error instead of warning for deprecation level HIDDEN
Since functions usually are hidden from resolution when they are deprecated-hidden, the problem can only be reproduced for properties with deprecated-hidden accessors, where DeprecatedCallChecker reported warnings instead of errors
This commit is contained in:
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.diagnostics.Diagnostic
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.resolve.DeprecationLevelValue.*
|
||||
import org.jetbrains.kotlin.resolve.annotations.argumentValue
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import java.util.*
|
||||
@@ -46,10 +47,10 @@ private data class DeprecatedByAnnotation(private val annotation: AnnotationDesc
|
||||
val level = annotation.argumentValue("level") as? ClassDescriptor
|
||||
|
||||
return when (level?.name?.asString()) {
|
||||
"WARNING" -> DeprecationLevelValue.WARNING
|
||||
"ERROR" -> DeprecationLevelValue.ERROR
|
||||
"HIDDEN" -> DeprecationLevelValue.HIDDEN
|
||||
else -> DeprecationLevelValue.WARNING
|
||||
"WARNING" -> WARNING
|
||||
"ERROR" -> ERROR
|
||||
"HIDDEN" -> HIDDEN
|
||||
else -> WARNING
|
||||
}
|
||||
}
|
||||
|
||||
@@ -172,11 +173,12 @@ private fun DeclarationDescriptor.getDeclaredDeprecatedAnnotation(
|
||||
|
||||
internal fun createDeprecationDiagnostic(element: PsiElement, deprecation: Deprecation): Diagnostic {
|
||||
val targetOriginal = deprecation.target.original
|
||||
if (deprecation.deprecationLevel == DeprecationLevelValue.ERROR) {
|
||||
return Errors.DEPRECATION_ERROR.on(element, targetOriginal, deprecation.message)
|
||||
val diagnosticFactory = when (deprecation.deprecationLevel) {
|
||||
WARNING -> Errors.DEPRECATION
|
||||
ERROR -> Errors.DEPRECATION_ERROR
|
||||
HIDDEN -> Errors.DEPRECATION_ERROR
|
||||
}
|
||||
|
||||
return Errors.DEPRECATION.on(element, targetOriginal, deprecation.message)
|
||||
return diagnosticFactory.on(element, targetOriginal, deprecation.message)
|
||||
}
|
||||
|
||||
// values from kotlin.DeprecationLevel
|
||||
@@ -185,7 +187,7 @@ enum class DeprecationLevelValue {
|
||||
}
|
||||
|
||||
fun DeclarationDescriptor.isDeprecatedHidden(): Boolean {
|
||||
return getDeprecation()?.deprecationLevel == DeprecationLevelValue.HIDDEN
|
||||
return getDeprecation()?.deprecationLevel == HIDDEN
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
|
||||
+1
-1
@@ -131,5 +131,5 @@ fun use(
|
||||
ned.p = 1
|
||||
|
||||
diff.<!DEPRECATION!>p<!>
|
||||
diff.<!DEPRECATION, DEPRECATION!>p<!> = 1
|
||||
diff.<!DEPRECATION, DEPRECATION_ERROR!>p<!> = 1
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
val v1: String
|
||||
@Deprecated("", level = DeprecationLevel.HIDDEN)
|
||||
get() = ""
|
||||
|
||||
@Deprecated("", level = DeprecationLevel.HIDDEN)
|
||||
val v2 = ""
|
||||
|
||||
var v3: String
|
||||
@Deprecated("", level = DeprecationLevel.HIDDEN)
|
||||
get() = ""
|
||||
set(value) {}
|
||||
|
||||
var v4: String
|
||||
get() = ""
|
||||
@Deprecated("", level = DeprecationLevel.HIDDEN)
|
||||
set(value) {}
|
||||
|
||||
var v5: String
|
||||
@Deprecated("", level = DeprecationLevel.HIDDEN)
|
||||
get() = ""
|
||||
@Deprecated("", level = DeprecationLevel.HIDDEN)
|
||||
set(value) {}
|
||||
|
||||
@Deprecated("", level = DeprecationLevel.HIDDEN)
|
||||
var v6: String
|
||||
get() = ""
|
||||
set(value) {}
|
||||
|
||||
fun test() {
|
||||
<!DEPRECATION_ERROR!>v1<!>
|
||||
<!UNRESOLVED_REFERENCE!>v2<!>
|
||||
<!DEPRECATION_ERROR!>v3<!>
|
||||
v3 = ""
|
||||
v4
|
||||
<!DEPRECATION_ERROR!>v4<!> = ""
|
||||
<!DEPRECATION_ERROR!>v5<!>
|
||||
<!DEPRECATION_ERROR!>v5<!> = ""
|
||||
<!UNRESOLVED_REFERENCE!>v6<!>
|
||||
<!UNRESOLVED_REFERENCE!>v6<!> = ""
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package
|
||||
|
||||
public val v1: kotlin.String
|
||||
@kotlin.Deprecated(level = DeprecationLevel.HIDDEN, message = "") public val v2: kotlin.String = ""
|
||||
public var v3: kotlin.String
|
||||
public var v4: kotlin.String
|
||||
public var v5: kotlin.String
|
||||
@kotlin.Deprecated(level = DeprecationLevel.HIDDEN, message = "") public var v6: kotlin.String
|
||||
public fun test(): kotlin.Unit
|
||||
@@ -5952,6 +5952,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("hiddenPropertyAccessors.kt")
|
||||
public void testHiddenPropertyAccessors() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/deprecated/hiddenPropertyAccessors.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("importJavaSamInterface.kt")
|
||||
public void testImportJavaSamInterface() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/deprecated/importJavaSamInterface.kt");
|
||||
|
||||
Reference in New Issue
Block a user