Pass builtIns into CompileTimeConstantChecker constructor

This commit is contained in:
Pavel V. Talanov
2015-09-21 15:53:45 +03:00
parent 9b0970e1a9
commit a72b050d91
4 changed files with 9 additions and 16 deletions
@@ -43,9 +43,13 @@ public class CompileTimeConstantChecker {
private final BindingTrace trace;
private final boolean checkOnlyErrorsThatDependOnExpectedType;
public CompileTimeConstantChecker(@NotNull BindingTrace trace, boolean checkOnlyErrorsThatDependOnExpectedType) {
public CompileTimeConstantChecker(
@NotNull BindingTrace trace,
@NotNull KotlinBuiltIns builtIns,
boolean checkOnlyErrorsThatDependOnExpectedType
) {
this.checkOnlyErrorsThatDependOnExpectedType = checkOnlyErrorsThatDependOnExpectedType;
this.builtIns = KotlinBuiltIns.getInstance();
this.builtIns = builtIns;
this.trace = trace;
}
@@ -120,9 +120,9 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
);
if (!(compileTimeConstant instanceof IntegerValueTypeConstant)) {
CompileTimeConstantChecker compileTimeConstantChecker = context.getCompileTimeConstantChecker();
CompileTimeConstantChecker constantChecker = new CompileTimeConstantChecker(context.trace, components.builtIns, false);
ConstantValue constantValue = compileTimeConstant != null ? ((TypedCompileTimeConstant) compileTimeConstant).getConstantValue() : null;
boolean hasError = compileTimeConstantChecker.checkConstantExpressionType(constantValue, expression, context.expectedType);
boolean hasError = constantChecker.checkConstantExpressionType(constantValue, expression, context.expectedType);
if (hasError) {
IElementType elementType = expression.getNode().getElementType();
return TypeInfoFactoryPackage.createTypeInfo(getDefaultType(elementType), context);
@@ -178,7 +178,7 @@ public class DataFlowAnalyzer {
if (expression instanceof JetConstantExpression) {
ConstantValue<?> constantValue = constantExpressionEvaluator.evaluateToConstantValue(expression, c.trace, c.expectedType);
boolean error = new CompileTimeConstantChecker(c.trace, true)
boolean error = new CompileTimeConstantChecker(c.trace, builtIns, true)
.checkConstantExpressionType(constantValue, (JetConstantExpression) expression, c.expectedType);
if (hasError != null) hasError.set(error);
return expressionType;
@@ -83,8 +83,6 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
statementFilter, isAnnotationContext, false, false);
}
private CompileTimeConstantChecker compileTimeConstantChecker;
private ExpressionTypingContext(
@NotNull BindingTrace trace,
@NotNull LexicalScope scope,
@@ -120,13 +118,4 @@ public class ExpressionTypingContext extends ResolutionContext<ExpressionTypingC
callChecker,
statementFilter, isAnnotationContext, collectAllCandidates, insideSafeCallChain);
}
///////////// LAZY ACCESSORS
public CompileTimeConstantChecker getCompileTimeConstantChecker() {
if (compileTimeConstantChecker == null) {
compileTimeConstantChecker = new CompileTimeConstantChecker(trace, false);
}
return compileTimeConstantChecker;
}
}