diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java index 5abb65fbc7c..47141987adb 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java @@ -127,7 +127,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { boolean hasError = compileTimeConstantChecker.checkConstantExpressionType(value, expression, context.expectedType); if (hasError) { IElementType elementType = expression.getNode().getElementType(); - return JetTypeInfo.create(getDefaultType(elementType), context.dataFlowInfo); + return JetTypeInfo.create(components.expressionTypingUtils.getDefaultType(elementType), context.dataFlowInfo); } } @@ -989,7 +989,8 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { if (resolutionResults.isSuccess()) { FunctionDescriptor equals = resolutionResults.getResultingCall().getResultingDescriptor(); - if (ensureBooleanResult(operationSign, OperatorConventions.EQUALS, equals.getReturnType(), context)) { + if (components.expressionTypingUtils.ensureBooleanResult(operationSign, OperatorConventions.EQUALS, equals.getReturnType(), + context)) { ensureNonemptyIntersectionOfOperandTypes(expression, context); } } @@ -1119,7 +1120,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { operationSign, OperatorConventions.CONTAINS); JetType containsType = OverloadResolutionResultsUtil.getResultingType(resolutionResult, context.contextDependency); - ensureBooleanResult(operationSign, OperatorConventions.CONTAINS, containsType, context); + components.expressionTypingUtils.ensureBooleanResult(operationSign, OperatorConventions.CONTAINS, containsType, context); if (left != null) { dataFlowInfo = facade.getTypeInfo(left, contextWithDataFlow).getDataFlowInfo().and(dataFlowInfo); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingVisitor.java index d20d9a17493..3561a123838 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingVisitor.java @@ -67,7 +67,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { .replaceExpectedType(components.builtIns.getBooleanType()).replaceContextDependency(INDEPENDENT)); JetType conditionType = typeInfo.getType(); - if (conditionType != null && !isBoolean(conditionType)) { + if (conditionType != null && !components.expressionTypingUtils.isBoolean(conditionType)) { context.trace.report(TYPE_MISMATCH_IN_CONDITION.on(condition, conditionType)); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingUtils.java index 939d4f6e46a..ae90abfeff5 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ExpressionTypingUtils.java @@ -109,19 +109,19 @@ public class ExpressionTypingUtils { return scope; } - public static boolean isBoolean(@NotNull JetType type) { - return JetTypeChecker.DEFAULT.isSubtypeOf(type, KotlinBuiltIns.getInstance().getBooleanType()); + public boolean isBoolean(@NotNull JetType type) { + return JetTypeChecker.DEFAULT.isSubtypeOf(type, builtIns.getBooleanType()); } - public static boolean ensureBooleanResult(JetExpression operationSign, Name name, JetType resultType, ExpressionTypingContext context) { + public boolean ensureBooleanResult(JetExpression operationSign, Name name, JetType resultType, ExpressionTypingContext context) { return ensureBooleanResultWithCustomSubject(operationSign, resultType, "'" + name + "'", context); } - public static boolean ensureBooleanResultWithCustomSubject(JetExpression operationSign, JetType resultType, String subjectName, ExpressionTypingContext context) { + private boolean ensureBooleanResultWithCustomSubject(JetExpression operationSign, JetType resultType, String subjectName, ExpressionTypingContext context) { if (resultType != null) { // TODO : Relax? if (!isBoolean(resultType)) { - context.trace.report(RESULT_TYPE_MISMATCH.on(operationSign, subjectName, KotlinBuiltIns.getInstance().getBooleanType(), resultType)); + context.trace.report(RESULT_TYPE_MISMATCH.on(operationSign, subjectName, builtIns.getBooleanType(), resultType)); return false; } } @@ -129,21 +129,21 @@ public class ExpressionTypingUtils { } @NotNull - public static JetType getDefaultType(IElementType constantType) { + public JetType getDefaultType(IElementType constantType) { if (constantType == JetNodeTypes.INTEGER_CONSTANT) { - return KotlinBuiltIns.getInstance().getIntType(); + return builtIns.getIntType(); } else if (constantType == JetNodeTypes.FLOAT_CONSTANT) { - return KotlinBuiltIns.getInstance().getDoubleType(); + return builtIns.getDoubleType(); } else if (constantType == JetNodeTypes.BOOLEAN_CONSTANT) { - return KotlinBuiltIns.getInstance().getBooleanType(); + return builtIns.getBooleanType(); } else if (constantType == JetNodeTypes.CHARACTER_CONSTANT) { - return KotlinBuiltIns.getInstance().getCharType(); + return builtIns.getCharType(); } else if (constantType == JetNodeTypes.NULL) { - return KotlinBuiltIns.getInstance().getNullableNothingType(); + return builtIns.getNullableNothingType(); } else { throw new IllegalArgumentException("Unsupported constant type: " + constantType); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ForLoopConventionsChecker.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ForLoopConventionsChecker.java index 0e284842979..ce27b55ce77 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ForLoopConventionsChecker.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ForLoopConventionsChecker.java @@ -43,7 +43,6 @@ import java.util.Collections; import static org.jetbrains.jet.lang.diagnostics.Errors.*; import static org.jetbrains.jet.lang.psi.PsiPackage.JetPsiFactory; import static org.jetbrains.jet.lang.resolve.BindingContext.*; -import static org.jetbrains.jet.lang.types.expressions.ExpressionTypingUtils.isBoolean; public class ForLoopConventionsChecker { @@ -98,7 +97,7 @@ public class ForLoopConventionsChecker { JetType hasNextType = checkConventionForIterator(context, loopRangeExpression, iteratorType, "hasNext", HAS_NEXT_FUNCTION_AMBIGUITY, HAS_NEXT_MISSING, HAS_NEXT_FUNCTION_NONE_APPLICABLE, LOOP_RANGE_HAS_NEXT_RESOLVED_CALL); - if (hasNextType != null && !isBoolean(hasNextType)) { + if (hasNextType != null && !expressionTypingUtils.isBoolean(hasNextType)) { context.trace.report(HAS_NEXT_FUNCTION_TYPE_MISMATCH.on(loopRangeExpression, hasNextType)); } return checkConventionForIterator(context, loopRangeExpression, iteratorType, "next",