CompileTimeConstantUtils: use getConstant instead of evaluate
Hacky way to avoid passing builtins into this code
This commit is contained in:
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor;
|
|||||||
import org.jetbrains.kotlin.name.FqName;
|
import org.jetbrains.kotlin.name.FqName;
|
||||||
import org.jetbrains.kotlin.psi.JetExpression;
|
import org.jetbrains.kotlin.psi.JetExpression;
|
||||||
import org.jetbrains.kotlin.psi.JetParameter;
|
import org.jetbrains.kotlin.psi.JetParameter;
|
||||||
|
import org.jetbrains.kotlin.psi.JetPsiUtil;
|
||||||
import org.jetbrains.kotlin.psi.JetTypeReference;
|
import org.jetbrains.kotlin.psi.JetTypeReference;
|
||||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
|
||||||
import org.jetbrains.kotlin.resolve.constants.BooleanValue;
|
import org.jetbrains.kotlin.resolve.constants.BooleanValue;
|
||||||
@@ -131,9 +132,11 @@ public class CompileTimeConstantUtils {
|
|||||||
@NotNull BindingTrace trace,
|
@NotNull BindingTrace trace,
|
||||||
@Nullable Boolean expectedValue
|
@Nullable Boolean expectedValue
|
||||||
) {
|
) {
|
||||||
if (expression == null) return false;
|
JetExpression effectiveExpression = JetPsiUtil.deparenthesize(expression);
|
||||||
CompileTimeConstant<?> compileTimeConstant =
|
|
||||||
ConstantExpressionEvaluator.evaluate(expression, trace, KotlinBuiltIns.getInstance().getBooleanType());
|
if (effectiveExpression == null) return false;
|
||||||
|
|
||||||
|
CompileTimeConstant<?> compileTimeConstant = ConstantExpressionEvaluator.getConstant(effectiveExpression, trace.getBindingContext());
|
||||||
if (!(compileTimeConstant instanceof TypedCompileTimeConstant) || compileTimeConstant.getUsesVariableAsConstant()) return false;
|
if (!(compileTimeConstant instanceof TypedCompileTimeConstant) || compileTimeConstant.getUsesVariableAsConstant()) return false;
|
||||||
|
|
||||||
ConstantValue constantValue = ((TypedCompileTimeConstant) compileTimeConstant).getConstantValue();
|
ConstantValue constantValue = ((TypedCompileTimeConstant) compileTimeConstant).getConstantValue();
|
||||||
|
|||||||
@@ -0,0 +1,4 @@
|
|||||||
|
fun box() : String = when (true) {
|
||||||
|
((true)) -> "OK"
|
||||||
|
(1 == 2) -> "Not ok"
|
||||||
|
}
|
||||||
+6
@@ -7717,6 +7717,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("exhaustiveBoolean.kt")
|
||||||
|
public void testExhaustiveBoolean() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/when/exhaustiveBoolean.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("is.kt")
|
@TestMetadata("is.kt")
|
||||||
public void testIs() throws Exception {
|
public void testIs() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/when/is.kt");
|
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/when/is.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user