diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java index a6dc5e17d78ef8e1284688bb3842c09f7b4e640d..5a68ead15c6dd5d5a6ea3096dfca72b6cfe29f75 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/FirOldFrontendDiagnosticsTestGenerated.java @@ -32152,6 +32152,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/isNullOrEmpty.kt"); } + @Test + @TestMetadata("kt45243.kt") + public void testKt45243() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/kt45243.kt"); + } + @Test @TestMetadata("require.kt") public void testRequire() throws Exception { diff --git a/compiler/frontend/src/org/jetbrains/kotlin/contracts/ESDataFlowValue.kt b/compiler/frontend/src/org/jetbrains/kotlin/contracts/ESDataFlowValue.kt index ef85438c13b6fa845dc8944f59a5c41c2277fe31..6b8fd69d3cb952862e0795925a707e5b688d6252 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/contracts/ESDataFlowValue.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/contracts/ESDataFlowValue.kt @@ -78,6 +78,6 @@ class ESReceiverWithDataFlowValue( */ class ESLambda(val lambda: KtLambdaExpression) : AbstractESValue(null) { override fun accept(visitor: ESExpressionVisitor): T { - throw IllegalStateException("Lambdas shouldn't be visited by ESExpressionVisitor") + return visitor.visitLambda(this) } -} \ No newline at end of file +} diff --git a/compiler/resolution/src/org/jetbrains/kotlin/contracts/model/ESExpressionVisitor.kt b/compiler/resolution/src/org/jetbrains/kotlin/contracts/model/ESExpressionVisitor.kt index 9b54d54651d2e895e1b8d70078718a27e0ec83ef..3815d408c630ecc5f8b6a505667702503b7f4799 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/contracts/model/ESExpressionVisitor.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/contracts/model/ESExpressionVisitor.kt @@ -30,4 +30,7 @@ interface ESExpressionVisitor { fun visitConstant(esConstant: ESConstant): T fun visitReceiver(esReceiver: ESReceiver): T -} \ No newline at end of file + + // ESLambda is invisible in this module + fun visitLambda(lambda: ESValue): T +} diff --git a/compiler/resolution/src/org/jetbrains/kotlin/contracts/model/visitors/InfoCollector.kt b/compiler/resolution/src/org/jetbrains/kotlin/contracts/model/visitors/InfoCollector.kt index 428ff4fb8593327626f33eda20dcbc6d80435cd2..aad613fd532c40d5f61bc1b40abb3ae489b57957 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/contracts/model/visitors/InfoCollector.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/contracts/model/visitors/InfoCollector.kt @@ -17,10 +17,7 @@ package org.jetbrains.kotlin.contracts.model.visitors import org.jetbrains.kotlin.builtins.KotlinBuiltIns -import org.jetbrains.kotlin.contracts.model.ConditionalEffect -import org.jetbrains.kotlin.contracts.model.ESEffect -import org.jetbrains.kotlin.contracts.model.ESExpressionVisitor -import org.jetbrains.kotlin.contracts.model.MutableContextInfo +import org.jetbrains.kotlin.contracts.model.* import org.jetbrains.kotlin.contracts.model.structure.* class InfoCollector(private val observedEffect: ESEffect, private val builtIns: KotlinBuiltIns) : ESExpressionVisitor { @@ -83,6 +80,8 @@ class InfoCollector(private val observedEffect: ESEffect, private val builtIns: override fun visitReceiver(esReceiver: ESReceiver): MutableContextInfo = MutableContextInfo.EMPTY + override fun visitLambda(lambda: ESValue): MutableContextInfo = MutableContextInfo.EMPTY + private fun inverted(block: () -> R): R { isInverted = isInverted.not() val result = block() diff --git a/compiler/resolution/src/org/jetbrains/kotlin/contracts/model/visitors/Reducer.kt b/compiler/resolution/src/org/jetbrains/kotlin/contracts/model/visitors/Reducer.kt index 621dfa167b49ec347a76be0b74a1c86bc9776e72..1eb6a0ed9a1cab147ed7522f8aa103d3060d3acd 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/contracts/model/visitors/Reducer.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/contracts/model/visitors/Reducer.kt @@ -66,8 +66,8 @@ class Reducer(private val builtIns: KotlinBuiltIns) : ESExpressionVisitor assertNotNull(actual: T) { + contract { returns() implies (actual != null) } +} + +@ExperimentalContracts +fun test_1() { + assertNotNull { } +} + +@ExperimentalContracts +fun test_2() { + assertNotNull({ }) +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/kt45243.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/kt45243.kt new file mode 100644 index 0000000000000000000000000000000000000000..3059fd542a4e487b3a04f4cff45b9dad4bc3db74 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/kt45243.kt @@ -0,0 +1,19 @@ +// ISSUE: KT-45243 + +import kotlin.contracts.ExperimentalContracts +import kotlin.contracts.contract + +@ExperimentalContracts +fun assertNotNull(actual: T) { + contract { returns() implies (actual != null) } +} + +@ExperimentalContracts +fun test_1() { + assertNotNull { } +} + +@ExperimentalContracts +fun test_2() { + assertNotNull({ }) +} diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/kt45243.txt b/compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/kt45243.txt new file mode 100644 index 0000000000000000000000000000000000000000..69e961eeba8d983bc3f26ceb4deb74495601b441 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/kt45243.txt @@ -0,0 +1,8 @@ +package + +@kotlin.contracts.ExperimentalContracts public fun assertNotNull(/*0*/ actual: T): kotlin.Unit + Returns(WILDCARD) -> actual != null + +@kotlin.contracts.ExperimentalContracts public fun test_1(): kotlin.Unit +@kotlin.contracts.ExperimentalContracts public fun test_2(): kotlin.Unit + diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java index 8fea46e8a27b289bf5da23f4a36eb40d78832413..6c2f4c9a2e7d8a0c89e504a5c6f2cb8b3ba74c88 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/DiagnosticTestGenerated.java @@ -32248,6 +32248,12 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest { runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/isNullOrEmpty.kt"); } + @Test + @TestMetadata("kt45243.kt") + public void testKt45243() throws Exception { + runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/fromStdlib/kt45243.kt"); + } + @Test @TestMetadata("require.kt") public void testRequire() throws Exception {