[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
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user