[FE] Don't fail with exception if ESVisitor tries to visit ESLambda
#KT-45243 Fixed
This commit is contained in:
committed by
TeamCityServer
parent
f3135baba9
commit
74118930b4
+6
@@ -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 {
|
||||
|
||||
@@ -78,6 +78,6 @@ class ESReceiverWithDataFlowValue(
|
||||
*/
|
||||
class ESLambda(val lambda: KtLambdaExpression) : AbstractESValue(null) {
|
||||
override fun <T> accept(visitor: ESExpressionVisitor<T>): T {
|
||||
throw IllegalStateException("Lambdas shouldn't be visited by ESExpressionVisitor")
|
||||
return visitor.visitLambda(this)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,4 +30,7 @@ interface ESExpressionVisitor<out T> {
|
||||
fun visitConstant(esConstant: ESConstant): T
|
||||
|
||||
fun visitReceiver(esReceiver: ESReceiver): T
|
||||
}
|
||||
|
||||
// ESLambda is invisible in this module
|
||||
fun visitLambda(lambda: ESValue): T
|
||||
}
|
||||
|
||||
+3
-4
@@ -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<MutableContextInfo> {
|
||||
@@ -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 <R> inverted(block: () -> R): R {
|
||||
isInverted = isInverted.not()
|
||||
val result = block()
|
||||
|
||||
@@ -66,8 +66,8 @@ class Reducer(private val builtIns: KotlinBuiltIns) : ESExpressionVisitor<ESExpr
|
||||
return ESConstants.booleanValue(result.xor(isOperator.functor.isNegated))
|
||||
}
|
||||
|
||||
override fun visitEqual(equal: ESEqual): ESExpression {
|
||||
val reducedLeft = equal.left.accept(this) as ESValue
|
||||
override fun visitEqual(equal: ESEqual): ESExpression? {
|
||||
val reducedLeft = equal.left.accept(this) as ESValue? ?: return null
|
||||
val reducedRight = equal.right
|
||||
|
||||
if (reducedLeft is ESConstant) return ESConstants.booleanValue((reducedLeft == reducedRight).xor(equal.functor.isNegated))
|
||||
@@ -114,4 +114,8 @@ class Reducer(private val builtIns: KotlinBuiltIns) : ESExpressionVisitor<ESExpr
|
||||
override fun visitConstant(esConstant: ESConstant): ESConstant = esConstant
|
||||
|
||||
override fun visitReceiver(esReceiver: ESReceiver): ESReceiver = esReceiver
|
||||
|
||||
override fun visitLambda(lambda: ESValue): ESExpression? {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
+5
-6
@@ -16,10 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.contracts.model.visitors
|
||||
|
||||
import org.jetbrains.kotlin.contracts.model.Computation
|
||||
import org.jetbrains.kotlin.contracts.model.ESExpression
|
||||
import org.jetbrains.kotlin.contracts.model.ESExpressionVisitor
|
||||
import org.jetbrains.kotlin.contracts.model.ESTypeSubstitution
|
||||
import org.jetbrains.kotlin.contracts.model.*
|
||||
import org.jetbrains.kotlin.contracts.model.structure.*
|
||||
|
||||
/**
|
||||
@@ -60,9 +57,11 @@ class Substitutor(
|
||||
return CallComputation(ESBooleanType, or.functor.invokeWithArguments(left, right))
|
||||
}
|
||||
|
||||
override fun visitVariable(esVariable: ESVariable): Computation? = substitutions[esVariable] ?: esVariable
|
||||
override fun visitVariable(esVariable: ESVariable): Computation = substitutions[esVariable] ?: esVariable
|
||||
|
||||
override fun visitConstant(esConstant: ESConstant): Computation? = esConstant
|
||||
override fun visitConstant(esConstant: ESConstant): Computation = esConstant
|
||||
|
||||
override fun visitReceiver(esReceiver: ESReceiver): ESReceiver = esReceiver
|
||||
|
||||
override fun visitLambda(lambda: ESValue): Computation = lambda
|
||||
}
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// ISSUE: KT-45243
|
||||
|
||||
import kotlin.contracts.ExperimentalContracts
|
||||
import kotlin.contracts.contract
|
||||
|
||||
@ExperimentalContracts
|
||||
fun <T> assertNotNull(actual: T) {
|
||||
<!WRONG_IMPLIES_CONDITION!>contract { returns() implies (actual != null) }<!>
|
||||
}
|
||||
|
||||
@ExperimentalContracts
|
||||
fun test_1() {
|
||||
assertNotNull { }
|
||||
}
|
||||
|
||||
@ExperimentalContracts
|
||||
fun test_2() {
|
||||
assertNotNull({ })
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
// ISSUE: KT-45243
|
||||
|
||||
import kotlin.contracts.ExperimentalContracts
|
||||
import kotlin.contracts.contract
|
||||
|
||||
@ExperimentalContracts
|
||||
fun <T> assertNotNull(actual: T) {
|
||||
contract { returns() implies (actual != null) }
|
||||
}
|
||||
|
||||
@ExperimentalContracts
|
||||
fun test_1() {
|
||||
assertNotNull { }
|
||||
}
|
||||
|
||||
@ExperimentalContracts
|
||||
fun test_2() {
|
||||
assertNotNull({ })
|
||||
}
|
||||
+8
@@ -0,0 +1,8 @@
|
||||
package
|
||||
|
||||
@kotlin.contracts.ExperimentalContracts public fun </*0*/ T> 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
|
||||
|
||||
Generated
+6
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user