CompileTimeConstantUtils: use getConstant instead of evaluate

Hacky way to avoid passing builtins into this code
This commit is contained in:
Pavel V. Talanov
2015-07-20 19:57:43 +03:00
parent 855e3d2bf4
commit 4e0d2bc23c
3 changed files with 16 additions and 3 deletions
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.psi.JetExpression;
import org.jetbrains.kotlin.psi.JetParameter;
import org.jetbrains.kotlin.psi.JetPsiUtil;
import org.jetbrains.kotlin.psi.JetTypeReference;
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall;
import org.jetbrains.kotlin.resolve.constants.BooleanValue;
@@ -131,9 +132,11 @@ public class CompileTimeConstantUtils {
@NotNull BindingTrace trace,
@Nullable Boolean expectedValue
) {
if (expression == null) return false;
CompileTimeConstant<?> compileTimeConstant =
ConstantExpressionEvaluator.evaluate(expression, trace, KotlinBuiltIns.getInstance().getBooleanType());
JetExpression effectiveExpression = JetPsiUtil.deparenthesize(expression);
if (effectiveExpression == null) return false;
CompileTimeConstant<?> compileTimeConstant = ConstantExpressionEvaluator.getConstant(effectiveExpression, trace.getBindingContext());
if (!(compileTimeConstant instanceof TypedCompileTimeConstant) || compileTimeConstant.getUsesVariableAsConstant()) return false;
ConstantValue constantValue = ((TypedCompileTimeConstant) compileTimeConstant).getConstantValue();
@@ -0,0 +1,4 @@
fun box() : String = when (true) {
((true)) -> "OK"
(1 == 2) -> "Not ok"
}
@@ -7717,6 +7717,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
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")
public void testIs() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/when/is.kt");