KT-2166 Control flow analysis doesn't detect that a 'while(true)' loop never terminates
KT-2103 Compiler requires return statement after loop which never exits #KT-2166 Fixed #KT-2103 Fixed
This commit is contained in:
@@ -30,9 +30,13 @@ import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.constants.BooleanValue;
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstantResolver;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardClasses;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.expressions.OperatorConventions;
|
||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
import java.util.Iterator;
|
||||
@@ -477,7 +481,15 @@ public class JetControlFlowProcessor {
|
||||
if (condition != null) {
|
||||
value(condition, true);
|
||||
}
|
||||
builder.jumpOnFalse(loopInfo.getExitPoint());
|
||||
boolean conditionIsTrueConstant = false;
|
||||
if (condition instanceof JetConstantExpression && condition.getNode().getElementType() == JetNodeTypes.BOOLEAN_CONSTANT) {
|
||||
if (BooleanValue.TRUE == new CompileTimeConstantResolver().getBooleanValue(condition.getText(), JetStandardLibrary.getInstance().getBooleanType())) {
|
||||
conditionIsTrueConstant = true;
|
||||
}
|
||||
}
|
||||
if (!conditionIsTrueConstant) {
|
||||
builder.jumpOnFalse(loopInfo.getExitPoint());
|
||||
}
|
||||
|
||||
builder.bindLabel(loopInfo.getBodyEntryPoint());
|
||||
JetExpression body = expression.getBody();
|
||||
|
||||
+1
-3
@@ -38,11 +38,9 @@ public class CompileTimeConstantResolver {
|
||||
public static final ErrorValue OUT_OF_RANGE = new ErrorValue("The value is out of range");
|
||||
|
||||
private final JetStandardLibrary standardLibrary;
|
||||
private final BindingTrace trace;
|
||||
|
||||
public CompileTimeConstantResolver(@NotNull BindingTrace trace) {
|
||||
public CompileTimeConstantResolver() {
|
||||
this.standardLibrary = JetStandardLibrary.getInstance();
|
||||
this.trace = trace;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+1
-1
@@ -147,7 +147,7 @@ public class ExpressionTypingContext {
|
||||
|
||||
public CompileTimeConstantResolver getCompileTimeConstantResolver() {
|
||||
if (compileTimeConstantResolver == null) {
|
||||
compileTimeConstantResolver = new CompileTimeConstantResolver(trace);
|
||||
compileTimeConstantResolver = new CompileTimeConstantResolver();
|
||||
}
|
||||
return compileTimeConstantResolver;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user