Do not report deprecation on readBytes with API version < 1.3
#KT-26667 Fixed
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
package org.jetbrains.kotlin.resolve.deprecation
|
package org.jetbrains.kotlin.resolve.deprecation
|
||||||
|
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
|
import org.jetbrains.kotlin.config.ApiVersion
|
||||||
import org.jetbrains.kotlin.config.KotlinCompilerVersion
|
import org.jetbrains.kotlin.config.KotlinCompilerVersion
|
||||||
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
import org.jetbrains.kotlin.config.LanguageVersionSettings
|
||||||
import org.jetbrains.kotlin.config.MavenComparableVersion
|
import org.jetbrains.kotlin.config.MavenComparableVersion
|
||||||
@@ -134,6 +135,11 @@ class DeprecationResolver(
|
|||||||
return emptyList()
|
return emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is a temporary workaround before @DeprecatedSinceKotlin is introduced, see KT-23575
|
||||||
|
if (shouldSkipDeprecationOnKotlinIoReadBytes(this, languageVersionSettings)) {
|
||||||
|
return emptyList()
|
||||||
|
}
|
||||||
|
|
||||||
val result = SmartList<Deprecation>()
|
val result = SmartList<Deprecation>()
|
||||||
|
|
||||||
addDeprecationIfPresent(result)
|
addDeprecationIfPresent(result)
|
||||||
@@ -183,6 +189,15 @@ class DeprecationResolver(
|
|||||||
private val DeclarationDescriptor.isBuiltInOperatorMod: Boolean
|
private val DeclarationDescriptor.isBuiltInOperatorMod: Boolean
|
||||||
get() = this is FunctionDescriptor && this.isOperatorMod() && KotlinBuiltIns.isUnderKotlinPackage(this)
|
get() = this is FunctionDescriptor && this.isOperatorMod() && KotlinBuiltIns.isUnderKotlinPackage(this)
|
||||||
|
|
||||||
|
private fun shouldSkipDeprecationOnKotlinIoReadBytes(
|
||||||
|
descriptor: DeclarationDescriptor, languageVersionSettings: LanguageVersionSettings
|
||||||
|
): Boolean =
|
||||||
|
descriptor.name.asString() == "readBytes" &&
|
||||||
|
(descriptor.containingDeclaration as? PackageFragmentDescriptor)?.fqName?.asString() == "kotlin.io" &&
|
||||||
|
descriptor is FunctionDescriptor &&
|
||||||
|
descriptor.valueParameters.singleOrNull()?.type?.let(KotlinBuiltIns::isInt) == true &&
|
||||||
|
languageVersionSettings.apiVersion < ApiVersion.KOTLIN_1_3
|
||||||
|
|
||||||
private fun getDeprecationByCoroutinesVersion(target: DeclarationDescriptor): DeprecatedExperimentalCoroutine? {
|
private fun getDeprecationByCoroutinesVersion(target: DeclarationDescriptor): DeprecatedExperimentalCoroutine? {
|
||||||
if (target !is DeserializedMemberDescriptor) return null
|
if (target !is DeserializedMemberDescriptor) return null
|
||||||
|
|
||||||
|
|||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
import java.io.InputStream
|
||||||
|
|
||||||
|
fun InputStream.test() {
|
||||||
|
readBytes()
|
||||||
|
|
||||||
|
<!DEPRECATION!>readBytes<!>(1)
|
||||||
|
}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun java.io.InputStream.test(): kotlin.Unit
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
// !API_VERSION: 1.2
|
||||||
|
|
||||||
|
import java.io.InputStream
|
||||||
|
|
||||||
|
fun InputStream.test() {
|
||||||
|
readBytes()
|
||||||
|
|
||||||
|
readBytes(1)
|
||||||
|
}
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public fun java.io.InputStream.test(): kotlin.Unit
|
||||||
+23
@@ -2226,6 +2226,29 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/deprecated")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class Deprecated extends AbstractDiagnosticsTestWithStdLib {
|
||||||
|
private void runTest(String testDataFilePath) throws Exception {
|
||||||
|
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAllFilesPresentInDeprecated() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/deprecated"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("deprecationOnReadBytes.kt")
|
||||||
|
public void testDeprecationOnReadBytes() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/deprecated/deprecationOnReadBytes.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("noDeprecationOnReadBytes.kt")
|
||||||
|
public void testNoDeprecationOnReadBytes() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/deprecated/noDeprecationOnReadBytes.kt");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature")
|
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java
Generated
+23
@@ -2226,6 +2226,29 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/deprecated")
|
||||||
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
public static class Deprecated extends AbstractDiagnosticsTestWithStdLibUsingJavac {
|
||||||
|
private void runTest(String testDataFilePath) throws Exception {
|
||||||
|
KotlinTestUtils.runTest(this::doTest, TargetBackend.ANY, testDataFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testAllFilesPresentInDeprecated() throws Exception {
|
||||||
|
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/deprecated"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("deprecationOnReadBytes.kt")
|
||||||
|
public void testDeprecationOnReadBytes() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/deprecated/deprecationOnReadBytes.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("noDeprecationOnReadBytes.kt")
|
||||||
|
public void testNoDeprecationOnReadBytes() throws Exception {
|
||||||
|
runTest("compiler/testData/diagnostics/testsWithStdLib/deprecated/noDeprecationOnReadBytes.kt");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature")
|
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature")
|
||||||
@TestDataPath("$PROJECT_ROOT")
|
@TestDataPath("$PROJECT_ROOT")
|
||||||
@RunWith(JUnit3RunnerWithInners.class)
|
@RunWith(JUnit3RunnerWithInners.class)
|
||||||
|
|||||||
Reference in New Issue
Block a user