diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/extensionReceiver.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/extensionReceiver.kt new file mode 100644 index 00000000000..f34b254d12c --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/extensionReceiver.kt @@ -0,0 +1,38 @@ +// !LANGUAGE: +AllowContractsForCustomFunctions +UseReturnsEffect +// !USE_EXPERIMENTAL: kotlin.contracts.ExperimentalContracts +// !DIAGNOSTICS: -INVISIBLE_REFERENCE -INVISIBLE_MEMBER +// +// ISSUE: KT-28672 + +import kotlin.contracts.* + +fun CharSequence?.isNullOrEmpty(): Boolean { + contract { + returns(false) implies (this@isNullOrEmpty != null) + } + + return this == null || this.length == 0 +} + +fun smartcastOnReceiver(s: String?) { + with(s) { + if (isNullOrEmpty()) { + length + } + else { + length + } + } +} + +fun mixedReceiver(s: String?) { + if (!s.isNullOrEmpty()) { + with(s) { + length + } + } else { + with(s) { + length + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/extensionReceiver.txt b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/extensionReceiver.txt new file mode 100644 index 00000000000..04bbccbbcac --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/extensionReceiver.txt @@ -0,0 +1,7 @@ +package + +public fun mixedReceiver(/*0*/ s: kotlin.String?): kotlin.Unit +public fun smartcastOnReceiver(/*0*/ s: kotlin.String?): kotlin.Unit +public fun kotlin.CharSequence?.isNullOrEmpty(): kotlin.Boolean + Returns(FALSE) -> != null + diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java index 1396a91de58..a913f6217a8 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java @@ -1296,6 +1296,11 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/deeplyNested.kt"); } + @TestMetadata("extensionReceiver.kt") + public void testExtensionReceiver() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/extensionReceiver.kt"); + } + @TestMetadata("intersectingInfo.kt") public void testIntersectingInfo() throws Exception { runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/intersectingInfo.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java index c91ce0013c5..990b63e6031 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/javac/DiagnosticsTestWithStdLibUsingJavacGenerated.java @@ -1296,6 +1296,11 @@ public class DiagnosticsTestWithStdLibUsingJavacGenerated extends AbstractDiagno runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/deeplyNested.kt"); } + @TestMetadata("extensionReceiver.kt") + public void testExtensionReceiver() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/extensionReceiver.kt"); + } + @TestMetadata("intersectingInfo.kt") public void testIntersectingInfo() throws Exception { runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/intersectingInfo.kt");