Refactoring: TypeInfoFactory.createTypeInfo() without type -> noTypeInfo(), getNotNullType -> getTypeNotNull, nullability refined, style fixes
This commit is contained in:
@@ -82,7 +82,7 @@ public class BindingContextUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetType getNotNullType(
|
||||
public static JetType getTypeNotNull(
|
||||
@NotNull BindingContext bindingContext,
|
||||
@NotNull JetExpression expression
|
||||
) {
|
||||
@@ -160,7 +160,7 @@ public class BindingContextUtils {
|
||||
// NB: should never return null if expression is already processed
|
||||
if (!Boolean.TRUE.equals(context.get(BindingContext.PROCESSED, expression))) return null;
|
||||
JetTypeInfo result = context.get(BindingContext.EXPRESSION_TYPE_INFO, expression);
|
||||
return result != null ? result : TypeInfoFactoryPackage.createTypeInfo(DataFlowInfo.EMPTY);
|
||||
return result != null ? result : TypeInfoFactoryPackage.noTypeInfo(DataFlowInfo.EMPTY);
|
||||
}
|
||||
|
||||
public static boolean isExpressionWithValidReference(
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.psi.JetExpression
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||
import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext
|
||||
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.createTypeInfo
|
||||
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.noTypeInfo
|
||||
|
||||
public fun JetReturnExpression.getTargetFunctionDescriptor(context: BindingContext): FunctionDescriptor? {
|
||||
val targetLabel = getTargetLabel()
|
||||
@@ -63,7 +63,8 @@ public fun <C : ResolutionContext<C>> ResolutionContext<C>.recordScopeAndDataFlo
|
||||
trace.record(BindingContext.EXPRESSION_TYPE_INFO, expression, typeInfo.replaceDataFlowInfo(dataFlowInfo))
|
||||
}
|
||||
else if (dataFlowInfo != DataFlowInfo.EMPTY) {
|
||||
trace.record(BindingContext.EXPRESSION_TYPE_INFO, expression, createTypeInfo(dataFlowInfo))
|
||||
// Don't store anything in BindingTrace if it's simply an empty DataFlowInfo
|
||||
trace.record(BindingContext.EXPRESSION_TYPE_INFO, expression, noTypeInfo(dataFlowInfo))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -192,7 +192,7 @@ public class ArgumentTypeResolver {
|
||||
@NotNull ResolveArgumentsMode resolveArgumentsMode
|
||||
) {
|
||||
if (expression == null) {
|
||||
return TypeInfoFactoryPackage.createTypeInfo(context);
|
||||
return TypeInfoFactoryPackage.noTypeInfo(context);
|
||||
}
|
||||
if (isFunctionLiteralArgument(expression, context)) {
|
||||
return getFunctionLiteralTypeInfo(expression, getFunctionLiteralArgument(expression, context), context, resolveArgumentsMode);
|
||||
|
||||
+5
-5
@@ -158,7 +158,7 @@ public class CallExpressionResolver {
|
||||
}
|
||||
|
||||
temporaryForVariable.commit();
|
||||
return TypeInfoFactoryPackage.createTypeInfo(context);
|
||||
return TypeInfoFactoryPackage.noTypeInfo(context);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -201,7 +201,7 @@ public class CallExpressionResolver {
|
||||
context.trace.report(FUNCTION_CALL_EXPECTED.on(callExpression, callExpression, hasValueParameters));
|
||||
}
|
||||
if (functionDescriptor == null) {
|
||||
return TypeInfoFactoryPackage.createTypeInfo(context);
|
||||
return TypeInfoFactoryPackage.noTypeInfo(context);
|
||||
}
|
||||
if (functionDescriptor instanceof ConstructorDescriptor &&
|
||||
DescriptorUtils.isAnnotationClass(functionDescriptor.getContainingDeclaration())) {
|
||||
@@ -226,11 +226,11 @@ public class CallExpressionResolver {
|
||||
temporaryForVariable.commit();
|
||||
context.trace.report(FUNCTION_EXPECTED.on(calleeExpression, calleeExpression,
|
||||
type != null ? type : ErrorUtils.createErrorType("")));
|
||||
return TypeInfoFactoryPackage.createTypeInfo(context);
|
||||
return TypeInfoFactoryPackage.noTypeInfo(context);
|
||||
}
|
||||
}
|
||||
temporaryForFunction.commit();
|
||||
return TypeInfoFactoryPackage.createTypeInfo(context);
|
||||
return TypeInfoFactoryPackage.noTypeInfo(context);
|
||||
}
|
||||
|
||||
private static boolean canInstantiateAnnotationClass(@NotNull JetCallExpression expression) {
|
||||
@@ -265,7 +265,7 @@ public class CallExpressionResolver {
|
||||
else if (selectorExpression != null) {
|
||||
context.trace.report(ILLEGAL_SELECTOR.on(selectorExpression, selectorExpression.getText()));
|
||||
}
|
||||
return TypeInfoFactoryPackage.createTypeInfo(context);
|
||||
return TypeInfoFactoryPackage.noTypeInfo(context);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -66,7 +66,7 @@ public fun <D : CallableDescriptor> ResolvedCall<D>.getParameterForArgument(valu
|
||||
// call
|
||||
|
||||
public fun <C: ResolutionContext<C>> Call.hasUnresolvedArguments(context: ResolutionContext<C>): Boolean {
|
||||
val arguments = getValueArguments().map { it?.getArgumentExpression() }
|
||||
val arguments = getValueArguments().map { it.getArgumentExpression() }
|
||||
return arguments.any {
|
||||
argument ->
|
||||
val expressionType = argument?.let { context.trace.getBindingContext().getType(it) }
|
||||
@@ -135,7 +135,7 @@ public fun JetElement.getCall(context: BindingContext): Call? {
|
||||
}
|
||||
|
||||
public fun JetElement.getParentCall(context: BindingContext, strict: Boolean = true): Call? {
|
||||
val callExpressionTypes = array<Class<out JetElement>?>(
|
||||
val callExpressionTypes = arrayOf<Class<out JetElement>?>(
|
||||
javaClass<JetSimpleNameExpression>(), javaClass<JetCallElement>(), javaClass<JetBinaryExpression>(),
|
||||
javaClass<JetUnaryExpression>(), javaClass<JetArrayAccessExpression>())
|
||||
|
||||
|
||||
+18
-17
@@ -111,7 +111,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
public JetTypeInfo visitParenthesizedExpression(@NotNull JetParenthesizedExpression expression, ExpressionTypingContext context) {
|
||||
JetExpression innerExpression = expression.getExpression();
|
||||
if (innerExpression == null) {
|
||||
return TypeInfoFactoryPackage.createTypeInfo(context);
|
||||
return TypeInfoFactoryPackage.noTypeInfo(context);
|
||||
}
|
||||
return facade.getTypeInfo(innerExpression, context.replaceScope(context.scope));
|
||||
}
|
||||
@@ -287,7 +287,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
if (superTypeQualifier != null) {
|
||||
components.expressionTypingServices.getTypeResolver().resolveType(context.scope, superTypeQualifier, context.trace, true);
|
||||
}
|
||||
return TypeInfoFactoryPackage.createTypeInfo(context);
|
||||
return TypeInfoFactoryPackage.noTypeInfo(context);
|
||||
}
|
||||
|
||||
private JetType checkPossiblyQualifiedSuper(
|
||||
@@ -812,7 +812,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
: contextWithExpectedType.replaceContextDependency(INDEPENDENT).replaceExpectedType(NO_EXPECTED_TYPE);
|
||||
|
||||
JetExpression baseExpression = expression.getBaseExpression();
|
||||
if (baseExpression == null) return TypeInfoFactoryPackage.createTypeInfo(context);
|
||||
if (baseExpression == null) return TypeInfoFactoryPackage.noTypeInfo(context);
|
||||
|
||||
JetSimpleNameExpression operationSign = expression.getOperationReference();
|
||||
|
||||
@@ -953,7 +953,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
boolean isStatement
|
||||
) {
|
||||
JetExpression baseExpression = expression.getBaseExpression();
|
||||
if (baseExpression == null) return TypeInfoFactoryPackage.createTypeInfo(context);
|
||||
if (baseExpression == null) return TypeInfoFactoryPackage.noTypeInfo(context);
|
||||
|
||||
return facade.getTypeInfo(baseExpression, context, isStatement);
|
||||
}
|
||||
@@ -1079,7 +1079,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
}
|
||||
else {
|
||||
context.trace.report(UNSUPPORTED.on(operationSign, "Unknown operation"));
|
||||
result = TypeInfoFactoryPackage.createTypeInfo(context);
|
||||
result = TypeInfoFactoryPackage.noTypeInfo(context);
|
||||
}
|
||||
CompileTimeConstant<?> value = ConstantExpressionEvaluator.evaluate(
|
||||
expression, contextWithExpectedType.trace, contextWithExpectedType.expectedType
|
||||
@@ -1222,7 +1222,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
|
||||
if (left == null || right == null) {
|
||||
getTypeInfoOrNullType(left, context, facade);
|
||||
return TypeInfoFactoryPackage.createTypeInfo(context);
|
||||
return TypeInfoFactoryPackage.noTypeInfo(context);
|
||||
}
|
||||
|
||||
Call call = createCallForSpecialConstruction(expression, expression.getOperationReference(), Lists.newArrayList(left, right));
|
||||
@@ -1245,7 +1245,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
dataFlowInfo = dataFlowInfo.disequate(value, DataFlowValue.NULL);
|
||||
}
|
||||
JetType type = resolvedCall.getResultingDescriptor().getReturnType();
|
||||
if (type == null || rightType == null) return TypeInfoFactoryPackage.createTypeInfo(dataFlowInfo);
|
||||
if (type == null || rightType == null) return TypeInfoFactoryPackage.noTypeInfo(dataFlowInfo);
|
||||
|
||||
// Sometimes return type for special call for elvis operator might be nullable,
|
||||
// but result is not nullable if the right type is not nullable
|
||||
@@ -1255,6 +1255,8 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
if (context.contextDependency == DEPENDENT) {
|
||||
return TypeInfoFactoryPackage.createTypeInfo(type, dataFlowInfo);
|
||||
}
|
||||
|
||||
// If break or continue was possible, take condition check info as the jump info
|
||||
return TypeInfoFactoryPackage.createTypeInfo(DataFlowUtils.checkType(type, expression, context),
|
||||
dataFlowInfo,
|
||||
loopBreakContinuePossible,
|
||||
@@ -1273,7 +1275,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
ExpressionTypingContext contextWithNoExpectedType = context.replaceExpectedType(NO_EXPECTED_TYPE);
|
||||
if (right == null) {
|
||||
if (left != null) facade.getTypeInfo(left, contextWithNoExpectedType);
|
||||
return TypeInfoFactoryPackage.createTypeInfo(context);
|
||||
return TypeInfoFactoryPackage.noTypeInfo(context);
|
||||
}
|
||||
|
||||
JetTypeInfo rightTypeInfo = facade.getTypeInfo(right, contextWithNoExpectedType);
|
||||
@@ -1350,7 +1352,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
private JetTypeInfo assignmentIsNotAnExpressionError(JetBinaryExpression expression, ExpressionTypingContext context) {
|
||||
facade.checkStatementType(expression, context);
|
||||
context.trace.report(ASSIGNMENT_IN_EXPRESSION_CONTEXT.on(expression));
|
||||
return TypeInfoFactoryPackage.createTypeInfo(context);
|
||||
return TypeInfoFactoryPackage.noTypeInfo(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1370,7 +1372,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
//left here is a receiver, so it doesn't depend on expected type
|
||||
typeInfo = facade.getTypeInfo(left, context.replaceContextDependency(INDEPENDENT).replaceExpectedType(NO_EXPECTED_TYPE));
|
||||
} else {
|
||||
typeInfo = TypeInfoFactoryPackage.createTypeInfo(context);
|
||||
typeInfo = TypeInfoFactoryPackage.noTypeInfo(context);
|
||||
}
|
||||
ExpressionTypingContext contextWithDataFlow = context.replaceDataFlowInfo(typeInfo.getDataFlowInfo());
|
||||
|
||||
@@ -1396,7 +1398,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
@Override
|
||||
public JetTypeInfo visitDeclaration(@NotNull JetDeclaration dcl, ExpressionTypingContext context) {
|
||||
context.trace.report(DECLARATION_IN_ILLEGAL_CONTEXT.on(dcl));
|
||||
return TypeInfoFactoryPackage.createTypeInfo(context);
|
||||
return TypeInfoFactoryPackage.noTypeInfo(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1404,10 +1406,9 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
if (!JetPsiUtil.isLHSOfDot(expression)) {
|
||||
context.trace.report(PACKAGE_IS_NOT_AN_EXPRESSION.on(expression));
|
||||
}
|
||||
return TypeInfoFactoryPackage.createTypeInfo(context);
|
||||
return TypeInfoFactoryPackage.noTypeInfo(context);
|
||||
}
|
||||
|
||||
|
||||
private class StringTemplateVisitor extends JetVisitorVoid {
|
||||
|
||||
final ExpressionTypingContext context;
|
||||
@@ -1416,7 +1417,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
|
||||
StringTemplateVisitor(ExpressionTypingContext context) {
|
||||
this.context = context;
|
||||
this.typeInfo = TypeInfoFactoryPackage.createTypeInfo(context);
|
||||
this.typeInfo = TypeInfoFactoryPackage.noTypeInfo(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1460,7 +1461,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
|
||||
JetExpression baseExpression = expression.getBaseExpression();
|
||||
if (baseExpression == null) {
|
||||
return TypeInfoFactoryPackage.createTypeInfo(context);
|
||||
return TypeInfoFactoryPackage.noTypeInfo(context);
|
||||
}
|
||||
return facade.getTypeInfo(baseExpression, context, isStatement);
|
||||
}
|
||||
@@ -1468,7 +1469,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
@Override
|
||||
public JetTypeInfo visitJetElement(@NotNull JetElement element, ExpressionTypingContext context) {
|
||||
context.trace.report(UNSUPPORTED.on(element, getClass().getCanonicalName()));
|
||||
return TypeInfoFactoryPackage.createTypeInfo(context);
|
||||
return TypeInfoFactoryPackage.noTypeInfo(context);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -1488,7 +1489,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
@NotNull BindingTrace traceForResolveResult,
|
||||
boolean isGet) {
|
||||
JetExpression arrayExpression = arrayAccessExpression.getArrayExpression();
|
||||
if (arrayExpression == null) return TypeInfoFactoryPackage.createTypeInfo(oldContext);
|
||||
if (arrayExpression == null) return TypeInfoFactoryPackage.noTypeInfo(oldContext);
|
||||
|
||||
|
||||
JetTypeInfo arrayTypeInfo = facade.safeGetTypeInfo(arrayExpression, oldContext.replaceExpectedType(NO_EXPECTED_TYPE)
|
||||
|
||||
+8
-7
@@ -111,8 +111,8 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
||||
: result;
|
||||
}
|
||||
return TypeInfoFactoryPackage.createTypeInfo(DataFlowUtils.checkImplicitCast(
|
||||
components.builtIns.getUnitType(), ifExpression,
|
||||
contextWithExpectedType, isStatement
|
||||
components.builtIns.getUnitType(), ifExpression,
|
||||
contextWithExpectedType, isStatement
|
||||
),
|
||||
thenInfo.or(elseInfo)
|
||||
);
|
||||
@@ -221,8 +221,9 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
||||
bodyTypeInfo = components.expressionTypingServices.getBlockReturnedTypeWithWritableScope(
|
||||
scopeToExtend, Collections.singletonList(body),
|
||||
CoercionStrategy.NO_COERCION, context.replaceDataFlowInfo(conditionInfo));
|
||||
} else {
|
||||
bodyTypeInfo = TypeInfoFactoryPackage.createTypeInfo(conditionInfo);
|
||||
}
|
||||
else {
|
||||
bodyTypeInfo = TypeInfoFactoryPackage.noTypeInfo(conditionInfo);
|
||||
}
|
||||
|
||||
// Condition is false at this point only if there is no jumps outside
|
||||
@@ -331,7 +332,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
||||
writableScope, block, CoercionStrategy.NO_COERCION, context);
|
||||
}
|
||||
else {
|
||||
bodyTypeInfo = TypeInfoFactoryPackage.createTypeInfo(context);
|
||||
bodyTypeInfo = TypeInfoFactoryPackage.noTypeInfo(context);
|
||||
}
|
||||
JetExpression condition = expression.getCondition();
|
||||
DataFlowInfo conditionDataFlowInfo = checkCondition(conditionScope, condition, context);
|
||||
@@ -380,7 +381,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
||||
}
|
||||
}
|
||||
else {
|
||||
loopRangeInfo = TypeInfoFactoryPackage.createTypeInfo(context);
|
||||
loopRangeInfo = TypeInfoFactoryPackage.noTypeInfo(context);
|
||||
}
|
||||
|
||||
WritableScope loopScope = newWritableScopeImpl(context, "Scope with for-loop index");
|
||||
@@ -480,7 +481,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
JetTypeInfo result = TypeInfoFactoryPackage.createTypeInfo(context);
|
||||
JetTypeInfo result = TypeInfoFactoryPackage.noTypeInfo(context);
|
||||
if (finallyBlock != null) {
|
||||
result = facade.getTypeInfo(finallyBlock.getFinalExpression(),
|
||||
context.replaceExpectedType(NO_EXPECTED_TYPE));
|
||||
|
||||
@@ -225,7 +225,7 @@ public class DataFlowUtils {
|
||||
facade.checkStatementType(
|
||||
expression, context.replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE).replaceContextDependency(INDEPENDENT));
|
||||
context.trace.report(EXPRESSION_EXPECTED.on(expression, expression));
|
||||
return TypeInfoFactoryPackage.createTypeInfo(context);
|
||||
return TypeInfoFactoryPackage.noTypeInfo(context);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+2
-2
@@ -315,13 +315,13 @@ public class ExpressionTypingServices {
|
||||
@NotNull ExpressionTypingContext context
|
||||
) {
|
||||
if (block.isEmpty()) {
|
||||
return new JetTypeInfo(builtIns.getUnitType(), context.dataFlowInfo, false, context.dataFlowInfo);
|
||||
return TypeInfoFactoryPackage.createTypeInfo(builtIns.getUnitType(), context);
|
||||
}
|
||||
|
||||
ExpressionTypingInternals blockLevelVisitor = ExpressionTypingVisitorDispatcher.createForBlock(expressionTypingComponents, scope);
|
||||
ExpressionTypingContext newContext = context.replaceScope(scope).replaceExpectedType(NO_EXPECTED_TYPE);
|
||||
|
||||
JetTypeInfo result = TypeInfoFactoryPackage.createTypeInfo(context);
|
||||
JetTypeInfo result = TypeInfoFactoryPackage.noTypeInfo(context);
|
||||
// Jump point data flow info
|
||||
DataFlowInfo beforeJumpInfo = newContext.dataFlowInfo;
|
||||
boolean jumpOutPossible = false;
|
||||
|
||||
+1
-1
@@ -336,7 +336,7 @@ public class ExpressionTypingUtils {
|
||||
) {
|
||||
return expression != null
|
||||
? facade.getTypeInfo(expression, context)
|
||||
: TypeInfoFactoryPackage.createTypeInfo(context);
|
||||
: TypeInfoFactoryPackage.noTypeInfo(context);
|
||||
}
|
||||
|
||||
@SuppressWarnings("SuspiciousMethodCalls")
|
||||
|
||||
+7
-5
@@ -99,8 +99,9 @@ public class ExpressionTypingVisitorDispatcher extends JetVisitor<JetTypeInfo, E
|
||||
if (typeInfo.getType() != null) {
|
||||
return typeInfo;
|
||||
}
|
||||
return typeInfo.replaceType(ErrorUtils.createErrorType("Type for " + expression.getText())).replaceDataFlowInfo(
|
||||
context.dataFlowInfo);
|
||||
return typeInfo
|
||||
.replaceType(ErrorUtils.createErrorType("Type for " + expression.getText()))
|
||||
.replaceDataFlowInfo(context.dataFlowInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -131,7 +132,7 @@ public class ExpressionTypingVisitorDispatcher extends JetVisitor<JetTypeInfo, E
|
||||
}
|
||||
|
||||
@NotNull
|
||||
static private JetTypeInfo getTypeInfo(@NotNull JetExpression expression, ExpressionTypingContext context, JetVisitor<JetTypeInfo, ExpressionTypingContext> visitor) {
|
||||
private static JetTypeInfo getTypeInfo(@NotNull JetExpression expression, ExpressionTypingContext context, JetVisitor<JetTypeInfo, ExpressionTypingContext> visitor) {
|
||||
try {
|
||||
JetTypeInfo recordedTypeInfo = BindingContextUtils.getRecordedTypeInfo(expression, context.trace.getBindingContext());
|
||||
if (recordedTypeInfo != null) {
|
||||
@@ -141,7 +142,8 @@ public class ExpressionTypingVisitorDispatcher extends JetVisitor<JetTypeInfo, E
|
||||
try {
|
||||
result = expression.accept(visitor, context);
|
||||
// Some recursive definitions (object expressions) must put their types in the cache manually:
|
||||
if (Boolean.TRUE.equals(context.trace.get(BindingContext.PROCESSED, expression))) {
|
||||
//noinspection ConstantConditions
|
||||
if (context.trace.get(BindingContext.PROCESSED, expression)) {
|
||||
JetType type = context.trace.getBindingContext().getType(expression);
|
||||
return result.replaceType(type);
|
||||
}
|
||||
@@ -153,7 +155,7 @@ public class ExpressionTypingVisitorDispatcher extends JetVisitor<JetTypeInfo, E
|
||||
}
|
||||
catch (ReenteringLazyValueComputationException e) {
|
||||
context.trace.report(TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM.on(expression));
|
||||
result = TypeInfoFactoryPackage.createTypeInfo(context);
|
||||
result = TypeInfoFactoryPackage.noTypeInfo(context);
|
||||
}
|
||||
|
||||
context.trace.record(BindingContext.PROCESSED, expression);
|
||||
|
||||
+12
-12
@@ -155,7 +155,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
|
||||
}
|
||||
}
|
||||
else {
|
||||
typeInfo = TypeInfoFactoryPackage.createTypeInfo(context);
|
||||
typeInfo = TypeInfoFactoryPackage.noTypeInfo(context);
|
||||
}
|
||||
|
||||
{
|
||||
@@ -176,13 +176,13 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
|
||||
JetExpression initializer = multiDeclaration.getInitializer();
|
||||
if (initializer == null) {
|
||||
context.trace.report(INITIALIZER_REQUIRED_FOR_MULTIDECLARATION.on(multiDeclaration));
|
||||
return TypeInfoFactoryPackage.createTypeInfo(context);
|
||||
return TypeInfoFactoryPackage.noTypeInfo(context);
|
||||
}
|
||||
ExpressionReceiver expressionReceiver = ExpressionTypingUtils.getExpressionReceiver(
|
||||
facade, initializer, context.replaceExpectedType(NO_EXPECTED_TYPE).replaceContextDependency(INDEPENDENT));
|
||||
JetTypeInfo typeInfo = facade.getTypeInfo(initializer, context);
|
||||
if (expressionReceiver == null) {
|
||||
return TypeInfoFactoryPackage.createTypeInfo(context);
|
||||
return TypeInfoFactoryPackage.noTypeInfo(context);
|
||||
}
|
||||
components.expressionTypingUtils.defineLocalVariablesFromMultiDeclaration(scope, multiDeclaration, expressionReceiver, initializer, context);
|
||||
return typeInfo.replaceType(DataFlowUtils.checkStatementType(multiDeclaration, context));
|
||||
@@ -339,7 +339,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
|
||||
JetExpression right = expression.getRight();
|
||||
if (left instanceof JetArrayAccessExpression) {
|
||||
JetArrayAccessExpression arrayAccessExpression = (JetArrayAccessExpression) left;
|
||||
if (right == null) return TypeInfoFactoryPackage.createTypeInfo(context);
|
||||
if (right == null) return TypeInfoFactoryPackage.noTypeInfo(context);
|
||||
JetTypeInfo typeInfo = basic.resolveArrayAccessSetMethod(arrayAccessExpression, right, context, context.trace);
|
||||
basic.checkLValue(context.trace, context, arrayAccessExpression, right);
|
||||
return typeInfo.replaceType(checkAssignmentType(typeInfo.getType(), expression, contextWithExpectedType));
|
||||
@@ -347,25 +347,25 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
|
||||
JetTypeInfo leftInfo = ExpressionTypingUtils.getTypeInfoOrNullType(left, context, facade);
|
||||
JetType leftType = leftInfo.getType();
|
||||
DataFlowInfo dataFlowInfo = leftInfo.getDataFlowInfo();
|
||||
JetTypeInfo rightInfo;
|
||||
JetTypeInfo resultInfo;
|
||||
if (right != null) {
|
||||
rightInfo = facade.getTypeInfo(right, context.replaceDataFlowInfo(dataFlowInfo).replaceExpectedType(leftType));
|
||||
dataFlowInfo = rightInfo.getDataFlowInfo();
|
||||
JetType rightType = rightInfo.getType();
|
||||
resultInfo = facade.getTypeInfo(right, context.replaceDataFlowInfo(dataFlowInfo).replaceExpectedType(leftType));
|
||||
dataFlowInfo = resultInfo.getDataFlowInfo();
|
||||
JetType rightType = resultInfo.getType();
|
||||
if (left != null && leftType != null && rightType != null) {
|
||||
DataFlowValue leftValue = DataFlowValueFactory.createDataFlowValue(left, leftType, context);
|
||||
DataFlowValue rightValue = DataFlowValueFactory.createDataFlowValue(right, rightType, context);
|
||||
// We cannot say here anything new about rightValue except it has the same value as leftValue
|
||||
rightInfo = rightInfo.replaceDataFlowInfo(dataFlowInfo.assign(leftValue, rightValue));
|
||||
resultInfo = resultInfo.replaceDataFlowInfo(dataFlowInfo.assign(leftValue, rightValue));
|
||||
}
|
||||
}
|
||||
else {
|
||||
rightInfo = leftInfo;
|
||||
resultInfo = leftInfo;
|
||||
}
|
||||
if (leftType != null && leftOperand != null) { //if leftType == null, some other error has been generated
|
||||
basic.checkLValue(context.trace, context, leftOperand, right);
|
||||
}
|
||||
return rightInfo.replaceType(DataFlowUtils.checkStatementType(expression, contextWithExpectedType));
|
||||
return resultInfo.replaceType(DataFlowUtils.checkStatementType(expression, contextWithExpectedType));
|
||||
}
|
||||
|
||||
|
||||
@@ -377,7 +377,7 @@ public class ExpressionTypingVisitorForStatements extends ExpressionTypingVisito
|
||||
@Override
|
||||
public JetTypeInfo visitJetElement(@NotNull JetElement element, ExpressionTypingContext context) {
|
||||
context.trace.report(UNSUPPORTED.on(element, "in a block"));
|
||||
return TypeInfoFactoryPackage.createTypeInfo(context);
|
||||
return TypeInfoFactoryPackage.noTypeInfo(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -42,6 +42,7 @@ import org.jetbrains.kotlin.types.checker.JetTypeChecker
|
||||
import org.jetbrains.kotlin.types.expressions.CoercionStrategy.COERCION_TO_UNIT
|
||||
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.createCheckedTypeInfo
|
||||
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.createTypeInfo
|
||||
import org.jetbrains.kotlin.types.expressions.typeInfoFactory.noTypeInfo
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
|
||||
public class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : ExpressionTypingVisitor(facade) {
|
||||
|
||||
+3
-2
@@ -51,8 +51,9 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
|
||||
|
||||
@Override
|
||||
public JetTypeInfo visitIsExpression(@NotNull JetIsExpression expression, ExpressionTypingContext contextWithExpectedType) {
|
||||
ExpressionTypingContext context = contextWithExpectedType.replaceExpectedType(NO_EXPECTED_TYPE).replaceContextDependency(
|
||||
INDEPENDENT);
|
||||
ExpressionTypingContext context = contextWithExpectedType
|
||||
.replaceExpectedType(NO_EXPECTED_TYPE)
|
||||
.replaceContextDependency(INDEPENDENT);
|
||||
JetExpression leftHandSide = expression.getLeftHandSide();
|
||||
JetTypeInfo typeInfo = facade.safeGetTypeInfo(leftHandSide, context.replaceScope(context.scope));
|
||||
JetType knownType = typeInfo.getType();
|
||||
|
||||
@@ -22,22 +22,22 @@ import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowInfo
|
||||
import org.jetbrains.kotlin.types.JetType
|
||||
import org.jetbrains.kotlin.types.expressions.JetTypeInfo
|
||||
|
||||
/**
|
||||
/*
|
||||
* Functions in this file are intended to create type info instances in different circumstances
|
||||
*/
|
||||
|
||||
public fun createTypeInfo(type: JetType?): JetTypeInfo = createTypeInfo(type, DataFlowInfo.EMPTY)
|
||||
|
||||
public fun createTypeInfo(dataFlowInfo: DataFlowInfo): JetTypeInfo = JetTypeInfo(null, dataFlowInfo)
|
||||
|
||||
public fun createTypeInfo(context: ResolutionContext<*>): JetTypeInfo = createTypeInfo(context.dataFlowInfo)
|
||||
|
||||
public fun createTypeInfo(type: JetType?, dataFlowInfo: DataFlowInfo): JetTypeInfo = JetTypeInfo(type, dataFlowInfo)
|
||||
|
||||
public fun createTypeInfo(type: JetType?, context: ResolutionContext<*>): JetTypeInfo = createTypeInfo(type, context.dataFlowInfo)
|
||||
|
||||
public fun createTypeInfo(type: JetType?, dataFlowInfo: DataFlowInfo, jumpPossible: Boolean, jumpFlowInfo: DataFlowInfo): JetTypeInfo =
|
||||
JetTypeInfo(type, dataFlowInfo, jumpPossible, jumpFlowInfo)
|
||||
|
||||
public fun createTypeInfo(type: JetType?): JetTypeInfo = createTypeInfo(type, DataFlowInfo.EMPTY)
|
||||
|
||||
public fun createTypeInfo(type: JetType?, context: ResolutionContext<*>): JetTypeInfo = createTypeInfo(type, context.dataFlowInfo)
|
||||
|
||||
public fun noTypeInfo(dataFlowInfo: DataFlowInfo): JetTypeInfo = createTypeInfo(null, dataFlowInfo)
|
||||
|
||||
public fun noTypeInfo(context: ResolutionContext<*>): JetTypeInfo = noTypeInfo(context.dataFlowInfo)
|
||||
|
||||
public fun createCheckedTypeInfo(type: JetType?, context: ResolutionContext<*>, expression: JetExpression): JetTypeInfo =
|
||||
createTypeInfo(type, context).checkType(expression, context)
|
||||
|
||||
+1
-1
@@ -356,7 +356,7 @@ public final class ExpressionVisitor extends TranslatorVisitor<JsNode> {
|
||||
assert right != null;
|
||||
|
||||
JetType rightType = BindingContextUtils.getNotNull(context.bindingContext(), BindingContext.TYPE, right);
|
||||
JetType leftType = BindingContextUtils.getNotNullType(context.bindingContext(), expression.getLeft());
|
||||
JetType leftType = BindingContextUtils.getTypeNotNull(context.bindingContext(), expression.getLeft());
|
||||
if (TypeUtils.isNullableType(rightType) || !TypeUtils.isNullableType(leftType)) {
|
||||
return jsExpression.source(expression);
|
||||
}
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ public final class UnaryOperationTranslator {
|
||||
IElementType operationToken = expression.getOperationReference().getReferencedNameElementType();
|
||||
if (operationToken == JetTokens.EXCLEXCL) {
|
||||
JetExpression baseExpression = getBaseExpression(expression);
|
||||
JetType type = BindingContextUtils.getNotNullType(context.bindingContext(), baseExpression);
|
||||
JetType type = BindingContextUtils.getTypeNotNull(context.bindingContext(), baseExpression);
|
||||
JsExpression translatedExpression = translateAsExpression(baseExpression, context);
|
||||
return type.isMarkedNullable() ? sure(translatedExpression, context) : translatedExpression;
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ public final class BindingUtils {
|
||||
@NotNull
|
||||
public static JetType getTypeForExpression(@NotNull BindingContext context,
|
||||
@NotNull JetExpression expression) {
|
||||
return BindingContextUtils.getNotNullType(context, expression);
|
||||
return BindingContextUtils.getTypeNotNull(context, expression);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
Reference in New Issue
Block a user