diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecation/DeprecationResolver.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecation/DeprecationResolver.kt index 69c0afef31f..9b17f22ea8e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecation/DeprecationResolver.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/deprecation/DeprecationResolver.kt @@ -6,6 +6,7 @@ package org.jetbrains.kotlin.resolve.deprecation import org.jetbrains.kotlin.builtins.KotlinBuiltIns +import org.jetbrains.kotlin.config.ApiVersion import org.jetbrains.kotlin.config.KotlinCompilerVersion import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.config.MavenComparableVersion @@ -134,6 +135,11 @@ class DeprecationResolver( return emptyList() } + // This is a temporary workaround before @DeprecatedSinceKotlin is introduced, see KT-23575 + if (shouldSkipDeprecationOnKotlinIoReadBytes(this, languageVersionSettings)) { + return emptyList() + } + val result = SmartList() addDeprecationIfPresent(result) @@ -183,6 +189,15 @@ class DeprecationResolver( private val DeclarationDescriptor.isBuiltInOperatorMod: Boolean 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? { if (target !is DeserializedMemberDescriptor) return null diff --git a/compiler/testData/diagnostics/testsWithStdLib/deprecated/deprecationOnReadBytes.kt b/compiler/testData/diagnostics/testsWithStdLib/deprecated/deprecationOnReadBytes.kt new file mode 100644 index 00000000000..2662e5662d2 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/deprecated/deprecationOnReadBytes.kt @@ -0,0 +1,7 @@ +import java.io.InputStream + +fun InputStream.test() { + readBytes() + + readBytes(1) +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/deprecated/deprecationOnReadBytes.txt b/compiler/testData/diagnostics/testsWithStdLib/deprecated/deprecationOnReadBytes.txt new file mode 100644 index 00000000000..570166cb82b --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/deprecated/deprecationOnReadBytes.txt @@ -0,0 +1,3 @@ +package + +public fun java.io.InputStream.test(): kotlin.Unit diff --git a/compiler/testData/diagnostics/testsWithStdLib/deprecated/noDeprecationOnReadBytes.kt b/compiler/testData/diagnostics/testsWithStdLib/deprecated/noDeprecationOnReadBytes.kt new file mode 100644 index 00000000000..df951011425 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/deprecated/noDeprecationOnReadBytes.kt @@ -0,0 +1,9 @@ +// !API_VERSION: 1.2 + +import java.io.InputStream + +fun InputStream.test() { + readBytes() + + readBytes(1) +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/deprecated/noDeprecationOnReadBytes.txt b/compiler/testData/diagnostics/testsWithStdLib/deprecated/noDeprecationOnReadBytes.txt new file mode 100644 index 00000000000..570166cb82b --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/deprecated/noDeprecationOnReadBytes.txt @@ -0,0 +1,3 @@ +package + +public fun java.io.InputStream.test(): kotlin.Unit diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java index a46ae753aab..d498c163360 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java @@ -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") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java index 7a141bb18f9..59ebaea78e5 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java @@ -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") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)