Rename: auto cast -> smart cast

This commit is contained in:
Svetlana Isakova
2014-09-29 23:09:05 +04:00
parent 20f3403c80
commit ce01c61811
294 changed files with 840 additions and 842 deletions
@@ -19,7 +19,7 @@ package org.jetbrains.jet.analyzer
import org.jetbrains.jet.lang.psi.JetExpression import org.jetbrains.jet.lang.psi.JetExpression
import org.jetbrains.jet.lang.resolve.scopes.JetScope import org.jetbrains.jet.lang.resolve.scopes.JetScope
import org.jetbrains.jet.di.InjectorForMacros import org.jetbrains.jet.di.InjectorForMacros
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo
import org.jetbrains.jet.lang.types.JetType import org.jetbrains.jet.lang.types.JetType
import org.jetbrains.jet.lang.types.TypeUtils import org.jetbrains.jet.lang.types.TypeUtils
import org.jetbrains.jet.lang.descriptors.ModuleDescriptor import org.jetbrains.jet.lang.descriptors.ModuleDescriptor
@@ -108,9 +108,9 @@ public class CheckerTestUtil {
}); });
// this code is used in tests and in internal action 'copy current file as diagnostic test' // this code is used in tests and in internal action 'copy current file as diagnostic test'
//noinspection TestOnlyProblems //noinspection TestOnlyProblems
for (JetExpression expression : bindingContext.getSliceContents(BindingContext.AUTOCAST).keySet()) { for (JetExpression expression : bindingContext.getSliceContents(BindingContext.SMARTCAST).keySet()) {
if (PsiTreeUtil.isAncestor(root, expression, false)) { if (PsiTreeUtil.isAncestor(root, expression, false)) {
debugAnnotations.add(new DebugInfoDiagnostic(expression, DebugInfoDiagnosticFactory.AUTOCAST)); debugAnnotations.add(new DebugInfoDiagnostic(expression, DebugInfoDiagnosticFactory.SMARTCAST));
} }
} }
return debugAnnotations; return debugAnnotations;
@@ -411,7 +411,7 @@ public class CheckerTestUtil {
} }
public static class DebugInfoDiagnosticFactory extends DiagnosticFactory<DebugInfoDiagnostic> { public static class DebugInfoDiagnosticFactory extends DiagnosticFactory<DebugInfoDiagnostic> {
public static final DebugInfoDiagnosticFactory AUTOCAST = new DebugInfoDiagnosticFactory("AUTOCAST"); public static final DebugInfoDiagnosticFactory SMARTCAST = new DebugInfoDiagnosticFactory("SMARTCAST");
public static final DebugInfoDiagnosticFactory ELEMENT_WITH_ERROR_TYPE = new DebugInfoDiagnosticFactory("ELEMENT_WITH_ERROR_TYPE"); public static final DebugInfoDiagnosticFactory ELEMENT_WITH_ERROR_TYPE = new DebugInfoDiagnosticFactory("ELEMENT_WITH_ERROR_TYPE");
public static final DebugInfoDiagnosticFactory UNRESOLVED_WITH_TARGET = new DebugInfoDiagnosticFactory("UNRESOLVED_WITH_TARGET"); public static final DebugInfoDiagnosticFactory UNRESOLVED_WITH_TARGET = new DebugInfoDiagnosticFactory("UNRESOLVED_WITH_TARGET");
public static final DebugInfoDiagnosticFactory MISSING_UNRESOLVED = new DebugInfoDiagnosticFactory("MISSING_UNRESOLVED"); public static final DebugInfoDiagnosticFactory MISSING_UNRESOLVED = new DebugInfoDiagnosticFactory("MISSING_UNRESOLVED");
@@ -531,7 +531,7 @@ public interface Errors {
DiagnosticFactory1<JetExpression, JetType> IMPLICIT_CAST_TO_UNIT_OR_ANY = DiagnosticFactory1.create(WARNING); DiagnosticFactory1<JetExpression, JetType> IMPLICIT_CAST_TO_UNIT_OR_ANY = DiagnosticFactory1.create(WARNING);
DiagnosticFactory2<JetExpression, JetType, String> AUTOCAST_IMPOSSIBLE = DiagnosticFactory2.create(ERROR); DiagnosticFactory2<JetExpression, JetType, String> SMARTCAST_IMPOSSIBLE = DiagnosticFactory2.create(ERROR);
DiagnosticFactory0<JetNullableType> USELESS_NULLABLE_CHECK = DiagnosticFactory0.create(WARNING, NULLABLE_TYPE); DiagnosticFactory0<JetNullableType> USELESS_NULLABLE_CHECK = DiagnosticFactory0.create(WARNING, NULLABLE_TYPE);
@@ -376,8 +376,8 @@ public class DefaultErrorMessages {
return typeConstraint.getSubjectTypeParameterName().getReferencedName(); return typeConstraint.getSubjectTypeParameterName().getReferencedName();
} }
}, DECLARATION_NAME); }, DECLARATION_NAME);
MAP.put(AUTOCAST_IMPOSSIBLE, MAP.put(SMARTCAST_IMPOSSIBLE,
"Automatic cast to ''{0}'' is impossible, because ''{1}'' could have changed since the is-check", RENDER_TYPE, STRING); "Smart cast to ''{0}'' is impossible, because ''{1}'' could have changed since the is-check", RENDER_TYPE, STRING);
MAP.put(VARIANCE_ON_TYPE_PARAMETER_OF_FUNCTION_OR_PROPERTY, "Variance annotations are only allowed for type parameters of classes and traits"); MAP.put(VARIANCE_ON_TYPE_PARAMETER_OF_FUNCTION_OR_PROPERTY, "Variance annotations are only allowed for type parameters of classes and traits");
MAP.put(REDUNDANT_PROJECTION, "Projection is redundant: the corresponding type parameter of {0} has the same variance", NAME); MAP.put(REDUNDANT_PROJECTION, "Projection is redundant: the corresponding type parameter of {0} has the same variance", NAME);
@@ -31,11 +31,11 @@ import org.jetbrains.jet.lang.evaluate.ConstantExpressionEvaluator;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.calls.ArgumentTypeResolver; import org.jetbrains.jet.lang.resolve.calls.ArgumentTypeResolver;
import org.jetbrains.jet.lang.resolve.calls.CallResolver; import org.jetbrains.jet.lang.resolve.calls.CallResolver;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.callUtil.CallUtilPackage; import org.jetbrains.jet.lang.resolve.calls.callUtil.CallUtilPackage;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedValueArgument; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedValueArgument;
import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults; import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.util.CallMaker; import org.jetbrains.jet.lang.resolve.calls.util.CallMaker;
import org.jetbrains.jet.lang.resolve.constants.ArrayValue; import org.jetbrains.jet.lang.resolve.constants.ArrayValue;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant; import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
@@ -27,9 +27,9 @@ import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor; import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.calls.TailRecursionKind; import org.jetbrains.jet.lang.resolve.calls.TailRecursionKind;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemCompleter; import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemCompleter;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant; import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
import org.jetbrains.jet.lang.resolve.name.FqName; import org.jetbrains.jet.lang.resolve.name.FqName;
import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe; import org.jetbrains.jet.lang.resolve.name.FqNameUnsafe;
@@ -120,7 +120,7 @@ public interface BindingContext {
WritableSlice<JetExpression, ResolvedCall<FunctionDescriptor>> INDEXED_LVALUE_GET = Slices.createSimpleSlice(); WritableSlice<JetExpression, ResolvedCall<FunctionDescriptor>> INDEXED_LVALUE_GET = Slices.createSimpleSlice();
WritableSlice<JetExpression, ResolvedCall<FunctionDescriptor>> INDEXED_LVALUE_SET = Slices.createSimpleSlice(); WritableSlice<JetExpression, ResolvedCall<FunctionDescriptor>> INDEXED_LVALUE_SET = Slices.createSimpleSlice();
WritableSlice<JetExpression, JetType> AUTOCAST = Slices.createSimpleSlice(); WritableSlice<JetExpression, JetType> SMARTCAST = Slices.createSimpleSlice();
WritableSlice<JetWhenExpression, Boolean> EXHAUSTIVE_WHEN = Slices.createSimpleSlice(); WritableSlice<JetWhenExpression, Boolean> EXHAUSTIVE_WHEN = Slices.createSimpleSlice();
@@ -25,10 +25,10 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage; import org.jetbrains.jet.lang.resolve.bindingContextUtil.BindingContextUtilPackage;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.callUtil.CallUtilPackage; import org.jetbrains.jet.lang.resolve.calls.callUtil.CallUtilPackage;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall; import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.JetTypeInfo; import org.jetbrains.jet.lang.types.JetTypeInfo;
import org.jetbrains.jet.lang.types.TypeUtils; import org.jetbrains.jet.lang.types.TypeUtils;
@@ -27,7 +27,7 @@ import org.jetbrains.jet.lang.psi.JetDeclarationWithBody
import org.jetbrains.jet.lang.resolve.DescriptorUtils import org.jetbrains.jet.lang.resolve.DescriptorUtils
import org.jetbrains.jet.lang.descriptors.impl.AnonymousFunctionDescriptor import org.jetbrains.jet.lang.descriptors.impl.AnonymousFunctionDescriptor
import org.jetbrains.jet.lang.psi.JetExpression import org.jetbrains.jet.lang.psi.JetExpression
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo
import org.jetbrains.jet.lang.resolve.calls.context.ResolutionContext import org.jetbrains.jet.lang.resolve.calls.context.ResolutionContext
public fun JetReturnExpression.getTargetFunctionDescriptor(context: BindingContext): FunctionDescriptor? { public fun JetReturnExpression.getTargetFunctionDescriptor(context: BindingContext): FunctionDescriptor? {
@@ -27,7 +27,7 @@ import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
import org.jetbrains.jet.lang.descriptors.ScriptDescriptor; import org.jetbrains.jet.lang.descriptors.ScriptDescriptor;
import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor; import org.jetbrains.jet.lang.descriptors.SimpleFunctionDescriptor;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo; import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.storage.ExceptionTracker; import org.jetbrains.jet.storage.ExceptionTracker;
import org.jetbrains.jet.storage.StorageManager; import org.jetbrains.jet.storage.StorageManager;
@@ -23,12 +23,12 @@ import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.diagnostics.rendering.Renderers; import org.jetbrains.jet.lang.diagnostics.rendering.Renderers;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.calls.CallResolver; import org.jetbrains.jet.lang.resolve.calls.CallResolver;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintPosition; import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintPosition;
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystem; import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystem;
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemCompleter; import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemCompleter;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults; import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.util.CallMaker; import org.jetbrains.jet.lang.resolve.calls.util.CallMaker;
import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScope;
@@ -31,7 +31,7 @@ import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory1;
import org.jetbrains.jet.lang.evaluate.ConstantExpressionEvaluator; import org.jetbrains.jet.lang.evaluate.ConstantExpressionEvaluator;
import org.jetbrains.jet.lang.evaluate.EvaluatePackage; import org.jetbrains.jet.lang.evaluate.EvaluatePackage;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo; import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant; import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
import org.jetbrains.jet.lang.resolve.constants.IntegerValueTypeConstant; import org.jetbrains.jet.lang.resolve.constants.IntegerValueTypeConstant;
import org.jetbrains.jet.lang.resolve.dataClassUtils.DataClassUtilsPackage; import org.jetbrains.jet.lang.resolve.dataClassUtils.DataClassUtilsPackage;
@@ -26,7 +26,7 @@ import org.jetbrains.jet.lang.psi.JetDeclaration;
import org.jetbrains.jet.lang.psi.JetNamedFunction; import org.jetbrains.jet.lang.psi.JetNamedFunction;
import org.jetbrains.jet.lang.psi.JetProperty; import org.jetbrains.jet.lang.psi.JetProperty;
import org.jetbrains.jet.lang.psi.JetScript; import org.jetbrains.jet.lang.psi.JetScript;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo; import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.lazy.ForceResolveUtil; import org.jetbrains.jet.lang.resolve.lazy.ForceResolveUtil;
import org.jetbrains.jet.lang.resolve.lazy.data.DataPackage; import org.jetbrains.jet.lang.resolve.lazy.data.DataPackage;
import org.jetbrains.jet.lang.resolve.scopes.WritableScope; import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
@@ -28,7 +28,7 @@ import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.descriptors.impl.MutableClassDescriptor; import org.jetbrains.jet.lang.descriptors.impl.MutableClassDescriptor;
import org.jetbrains.jet.lang.descriptors.impl.MutablePackageFragmentDescriptor; import org.jetbrains.jet.lang.descriptors.impl.MutablePackageFragmentDescriptor;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo; import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.WritableScope; import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
import org.jetbrains.jet.storage.ExceptionTracker; import org.jetbrains.jet.storage.ExceptionTracker;
@@ -36,7 +36,7 @@ import org.jetbrains.jet.lang.resolve.calls.results.ResolutionStatus
import org.jetbrains.jet.lang.resolve.calls.inference.InferenceErrorData import org.jetbrains.jet.lang.resolve.calls.inference.InferenceErrorData
import org.jetbrains.jet.lang.psi.ValueArgument import org.jetbrains.jet.lang.psi.ValueArgument
import org.jetbrains.jet.lang.resolve.calls.model.ArgumentMapping import org.jetbrains.jet.lang.resolve.calls.model.ArgumentMapping
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo
import org.jetbrains.jet.lang.resolve.calls.model.ArgumentUnmapped import org.jetbrains.jet.lang.resolve.calls.model.ArgumentUnmapped
import org.jetbrains.jet.lang.resolve.calls.model.ArgumentMatch import org.jetbrains.jet.lang.resolve.calls.model.ArgumentMatch
import org.jetbrains.jet.lang.resolve.BindingContext import org.jetbrains.jet.lang.resolve.BindingContext
@@ -25,7 +25,6 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.*; import org.jetbrains.jet.lang.resolve.*;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.callUtil.CallUtilPackage; import org.jetbrains.jet.lang.resolve.calls.callUtil.CallUtilPackage;
import org.jetbrains.jet.lang.resolve.calls.context.*; import org.jetbrains.jet.lang.resolve.calls.context.*;
import org.jetbrains.jet.lang.resolve.calls.model.MutableDataFlowInfoForArguments; import org.jetbrains.jet.lang.resolve.calls.model.MutableDataFlowInfoForArguments;
@@ -34,6 +33,7 @@ import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults; import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults;
import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResultsImpl; import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResultsImpl;
import org.jetbrains.jet.lang.resolve.calls.results.ResolutionResultsHandler; import org.jetbrains.jet.lang.resolve.calls.results.ResolutionResultsHandler;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.tasks.*; import org.jetbrains.jet.lang.resolve.calls.tasks.*;
import org.jetbrains.jet.lang.resolve.calls.util.CallMaker; import org.jetbrains.jet.lang.resolve.calls.util.CallMaker;
import org.jetbrains.jet.lang.resolve.calls.util.DelegatingCall; import org.jetbrains.jet.lang.resolve.calls.util.DelegatingCall;
@@ -26,16 +26,16 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.*; import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.*; import org.jetbrains.jet.lang.resolve.*;
import org.jetbrains.jet.lang.resolve.calls.autocasts.AutoCastUtils;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValue;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValueFactory;
import org.jetbrains.jet.lang.resolve.calls.context.*; import org.jetbrains.jet.lang.resolve.calls.context.*;
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintPosition; import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintPosition;
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystem; import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystem;
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemImpl; import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemImpl;
import org.jetbrains.jet.lang.resolve.calls.model.*; import org.jetbrains.jet.lang.resolve.calls.model.*;
import org.jetbrains.jet.lang.resolve.calls.results.ResolutionStatus; import org.jetbrains.jet.lang.resolve.calls.results.ResolutionStatus;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowValue;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowValueFactory;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.SmartCastUtils;
import org.jetbrains.jet.lang.resolve.calls.tasks.ResolutionTask; import org.jetbrains.jet.lang.resolve.calls.tasks.ResolutionTask;
import org.jetbrains.jet.lang.resolve.calls.tasks.TaskPrioritizer; import org.jetbrains.jet.lang.resolve.calls.tasks.TaskPrioritizer;
import org.jetbrains.jet.lang.resolve.calls.util.FakeCallableDescriptorForObject; import org.jetbrains.jet.lang.resolve.calls.util.FakeCallableDescriptorForObject;
@@ -501,13 +501,13 @@ public class CandidateResolver {
} }
else if (!noExpectedType(expectedType)) { else if (!noExpectedType(expectedType)) {
if (!ArgumentTypeResolver.isSubtypeOfForArgumentType(type, expectedType)) { if (!ArgumentTypeResolver.isSubtypeOfForArgumentType(type, expectedType)) {
JetType autocastType = autocastValueArgumentTypeIfPossible(expression, expectedType, type, newContext); JetType smartCastType = smartCastValueArgumentTypeIfPossible(expression, expectedType, type, newContext);
if (autocastType == null) { if (smartCastType == null) {
resultStatus = OTHER_ERROR; resultStatus = OTHER_ERROR;
matchStatus = ArgumentMatchStatus.TYPE_MISMATCH; matchStatus = ArgumentMatchStatus.TYPE_MISMATCH;
} }
else { else {
resultingType = autocastType; resultingType = smartCastType;
} }
} }
else if (ErrorUtils.containsUninferredParameter(expectedType)) { else if (ErrorUtils.containsUninferredParameter(expectedType)) {
@@ -522,7 +522,7 @@ public class CandidateResolver {
} }
@Nullable @Nullable
private static JetType autocastValueArgumentTypeIfPossible( private static JetType smartCastValueArgumentTypeIfPossible(
@NotNull JetExpression expression, @NotNull JetExpression expression,
@NotNull JetType expectedType, @NotNull JetType expectedType,
@NotNull JetType actualType, @NotNull JetType actualType,
@@ -530,7 +530,8 @@ public class CandidateResolver {
) { ) {
ExpressionReceiver receiverToCast = new ExpressionReceiver(JetPsiUtil.safeDeparenthesize(expression, false), actualType); ExpressionReceiver receiverToCast = new ExpressionReceiver(JetPsiUtil.safeDeparenthesize(expression, false), actualType);
List<JetType> variants = List<JetType> variants =
AutoCastUtils.getAutoCastVariantsExcludingReceiver(context.trace.getBindingContext(), context.dataFlowInfo, receiverToCast); SmartCastUtils.getSmartCastVariantsExcludingReceiver(context.trace.getBindingContext(), context.dataFlowInfo,
receiverToCast);
for (JetType possibleType : variants) { for (JetType possibleType : variants) {
if (JetTypeChecker.DEFAULT.isSubtypeOf(possibleType, expectedType)) { if (JetTypeChecker.DEFAULT.isSubtypeOf(possibleType, expectedType)) {
return possibleType; return possibleType;
@@ -568,8 +569,8 @@ public class CandidateResolver {
JetType erasedReceiverType = CallResolverUtil.getErasedReceiverType(receiverParameterDescriptor, candidateDescriptor); JetType erasedReceiverType = CallResolverUtil.getErasedReceiverType(receiverParameterDescriptor, candidateDescriptor);
boolean isSubtypeByAutoCast = AutoCastUtils.isSubTypeByAutoCastIgnoringNullability(receiverArgument, erasedReceiverType, context); boolean isSubtypeBySmartCast = SmartCastUtils.isSubTypeBySmartCastIgnoringNullability(receiverArgument, erasedReceiverType, context);
if (!isSubtypeByAutoCast) { if (!isSubtypeBySmartCast) {
return RECEIVER_TYPE_ERROR; return RECEIVER_TYPE_ERROR;
} }
@@ -590,19 +591,19 @@ public class CandidateResolver {
if (TypeUtils.dependsOnTypeParameters(receiverParameter.getType(), candidateDescriptor.getTypeParameters())) return SUCCESS; if (TypeUtils.dependsOnTypeParameters(receiverParameter.getType(), candidateDescriptor.getTypeParameters())) return SUCCESS;
boolean safeAccess = isExplicitReceiver && !implicitInvokeCheck && candidateCall.isSafeCall(); boolean safeAccess = isExplicitReceiver && !implicitInvokeCheck && candidateCall.isSafeCall();
boolean isSubtypeByAutoCast = AutoCastUtils.isSubTypeByAutoCastIgnoringNullability( boolean isSubtypeBySmartCast = SmartCastUtils.isSubTypeBySmartCastIgnoringNullability(
receiverArgument, receiverParameter.getType(), context); receiverArgument, receiverParameter.getType(), context);
if (!isSubtypeByAutoCast) { if (!isSubtypeBySmartCast) {
context.tracing.wrongReceiverType(trace, receiverParameter, receiverArgument); context.tracing.wrongReceiverType(trace, receiverParameter, receiverArgument);
return OTHER_ERROR; return OTHER_ERROR;
} }
AutoCastUtils.recordAutoCastIfNecessary(receiverArgument, receiverParameter.getType(), context, safeAccess); SmartCastUtils.recordSmartCastIfNecessary(receiverArgument, receiverParameter.getType(), context, safeAccess);
JetType receiverArgumentType = receiverArgument.getType(); JetType receiverArgumentType = receiverArgument.getType();
BindingContext bindingContext = trace.getBindingContext(); BindingContext bindingContext = trace.getBindingContext();
if (!safeAccess && !receiverParameter.getType().isNullable() && receiverArgumentType.isNullable()) { if (!safeAccess && !receiverParameter.getType().isNullable() && receiverArgumentType.isNullable()) {
if (!AutoCastUtils.isNotNull(receiverArgument, bindingContext, context.dataFlowInfo)) { if (!SmartCastUtils.isNotNull(receiverArgument, bindingContext, context.dataFlowInfo)) {
context.tracing.unsafeCall(trace, receiverArgumentType, implicitInvokeCheck); context.tracing.unsafeCall(trace, receiverArgumentType, implicitInvokeCheck);
return UNSAFE_CALL_ERROR; return UNSAFE_CALL_ERROR;
@@ -21,8 +21,8 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.psi.Call; import org.jetbrains.jet.lang.psi.Call;
import org.jetbrains.jet.lang.resolve.BindingTrace; import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.calls.CallResolverExtension; import org.jetbrains.jet.lang.resolve.calls.CallResolverExtension;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.model.MutableDataFlowInfoForArguments; import org.jetbrains.jet.lang.resolve.calls.model.MutableDataFlowInfoForArguments;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
@@ -22,9 +22,9 @@ import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
import org.jetbrains.jet.lang.psi.Call; import org.jetbrains.jet.lang.psi.Call;
import org.jetbrains.jet.lang.resolve.BindingTrace; import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.calls.CallResolverExtension; import org.jetbrains.jet.lang.resolve.calls.CallResolverExtension;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.model.MutableDataFlowInfoForArguments; import org.jetbrains.jet.lang.resolve.calls.model.MutableDataFlowInfoForArguments;
import org.jetbrains.jet.lang.resolve.calls.model.MutableResolvedCall; import org.jetbrains.jet.lang.resolve.calls.model.MutableResolvedCall;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.tasks.TracingStrategy; import org.jetbrains.jet.lang.resolve.calls.tasks.TracingStrategy;
import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue; import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverValue;
@@ -21,9 +21,9 @@ import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.psi.Call; import org.jetbrains.jet.lang.psi.Call;
import org.jetbrains.jet.lang.resolve.BindingTrace; import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.calls.CallResolverExtension; import org.jetbrains.jet.lang.resolve.calls.CallResolverExtension;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.model.DataFlowInfoForArgumentsImpl; import org.jetbrains.jet.lang.resolve.calls.model.DataFlowInfoForArgumentsImpl;
import org.jetbrains.jet.lang.resolve.calls.model.MutableDataFlowInfoForArguments; import org.jetbrains.jet.lang.resolve.calls.model.MutableDataFlowInfoForArguments;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
@@ -20,7 +20,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.BindingTrace; import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.calls.CallResolverExtension; import org.jetbrains.jet.lang.resolve.calls.CallResolverExtension;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo; import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeUtils; import org.jetbrains.jet.lang.types.TypeUtils;
@@ -19,7 +19,7 @@ package org.jetbrains.jet.lang.resolve.calls.context;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.resolve.BindingTrace; import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.calls.CallResolverExtension; import org.jetbrains.jet.lang.resolve.calls.CallResolverExtension;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo; import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
@@ -18,7 +18,7 @@ package org.jetbrains.jet.lang.resolve.calls.model;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.ValueArgument; import org.jetbrains.jet.lang.psi.ValueArgument;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo; import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
public interface DataFlowInfoForArguments { public interface DataFlowInfoForArguments {
@NotNull @NotNull
@@ -20,7 +20,7 @@ import com.google.common.collect.Maps;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.Call; import org.jetbrains.jet.lang.psi.Call;
import org.jetbrains.jet.lang.psi.ValueArgument; import org.jetbrains.jet.lang.psi.ValueArgument;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo; import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@@ -18,7 +18,7 @@ package org.jetbrains.jet.lang.resolve.calls.model;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.ValueArgument; import org.jetbrains.jet.lang.psi.ValueArgument;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo; import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
public interface MutableDataFlowInfoForArguments extends DataFlowInfoForArguments { public interface MutableDataFlowInfoForArguments extends DataFlowInfoForArguments {
@@ -22,7 +22,6 @@ import org.jetbrains.jet.lang.descriptors.CallableDescriptor;
import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor; import org.jetbrains.jet.lang.descriptors.ValueParameterDescriptor;
import org.jetbrains.jet.lang.psi.ValueArgument; import org.jetbrains.jet.lang.psi.ValueArgument;
import org.jetbrains.jet.lang.resolve.DelegatingBindingTrace; import org.jetbrains.jet.lang.resolve.DelegatingBindingTrace;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystem; import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystem;
import org.jetbrains.jet.lang.resolve.calls.results.ResolutionStatus; import org.jetbrains.jet.lang.resolve.calls.results.ResolutionStatus;
import org.jetbrains.jet.lang.types.TypeSubstitutor; import org.jetbrains.jet.lang.types.TypeSubstitutor;
@@ -45,7 +45,7 @@ public class OverloadingConflictResolver {
@NotNull Set<MutableResolvedCall<D>> candidates, @NotNull Set<MutableResolvedCall<D>> candidates,
boolean discriminateGenericDescriptors boolean discriminateGenericDescriptors
) { ) {
// Different autocasts may lead to the same candidate descriptor wrapped into different ResolvedCallImpl objects // Different smartcasts may lead to the same candidate descriptor wrapped into different ResolvedCallImpl objects
Set<MutableResolvedCall<D>> maximallySpecific = new THashSet<MutableResolvedCall<D>>(new TObjectHashingStrategy<MutableResolvedCall<D>>() { Set<MutableResolvedCall<D>> maximallySpecific = new THashSet<MutableResolvedCall<D>>(new TObjectHashingStrategy<MutableResolvedCall<D>>() {
@Override @Override
public boolean equals(MutableResolvedCall<D> o1, MutableResolvedCall<D> o2) { public boolean equals(MutableResolvedCall<D> o1, MutableResolvedCall<D> o2) {
@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.jetbrains.jet.lang.resolve.calls.autocasts; package org.jetbrains.jet.lang.resolve.calls.smartcasts;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.google.common.collect.SetMultimap; import com.google.common.collect.SetMultimap;
@@ -14,12 +14,12 @@
* limitations under the License. * limitations under the License.
*/ */
package org.jetbrains.jet.lang.resolve.calls.autocasts; package org.jetbrains.jet.lang.resolve.calls.smartcasts;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
public class DataFlowValue { public class DataFlowValue {
@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.jetbrains.jet.lang.resolve.calls.autocasts; package org.jetbrains.jet.lang.resolve.calls.smartcasts;
import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.Pair;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -59,7 +59,7 @@ public class DataFlowValueFactory {
@NotNull @NotNull
public static DataFlowValue createDataFlowValue(@NotNull ReceiverValue receiverValue, @NotNull BindingContext bindingContext) { public static DataFlowValue createDataFlowValue(@NotNull ReceiverValue receiverValue, @NotNull BindingContext bindingContext) {
if (receiverValue instanceof TransientReceiver || receiverValue instanceof ScriptReceiver) { if (receiverValue instanceof TransientReceiver || receiverValue instanceof ScriptReceiver) {
// SCRIPT: autocasts data flow // SCRIPT: smartcasts data flow
JetType type = receiverValue.getType(); JetType type = receiverValue.getType();
boolean nullable = type.isNullable() || TypeUtils.hasNullableSuperType(type); boolean nullable = type.isNullable() || TypeUtils.hasNullableSuperType(type);
return new DataFlowValue(receiverValue, type, nullable, Nullability.NOT_NULL); return new DataFlowValue(receiverValue, type, nullable, Nullability.NOT_NULL);
@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.jetbrains.jet.lang.resolve.calls.autocasts; package org.jetbrains.jet.lang.resolve.calls.smartcasts;
import com.google.common.collect.*; import com.google.common.collect.*;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -25,7 +25,7 @@ import org.jetbrains.jet.lang.types.TypeUtils;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import static org.jetbrains.jet.lang.resolve.calls.autocasts.Nullability.NOT_NULL; import static org.jetbrains.jet.lang.resolve.calls.smartcasts.Nullability.NOT_NULL;
/* package */ class DelegatingDataFlowInfo implements DataFlowInfo { /* package */ class DelegatingDataFlowInfo implements DataFlowInfo {
private static final ImmutableMap<DataFlowValue,Nullability> EMPTY_NULLABILITY_INFO = ImmutableMap.of(); private static final ImmutableMap<DataFlowValue,Nullability> EMPTY_NULLABILITY_INFO = ImmutableMap.of();
@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.jetbrains.jet.lang.resolve.calls.autocasts; package org.jetbrains.jet.lang.resolve.calls.smartcasts;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
package org.jetbrains.jet.lang.resolve.calls.autocasts; package org.jetbrains.jet.lang.resolve.calls.smartcasts;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
@@ -36,31 +36,31 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Set; import java.util.Set;
import static org.jetbrains.jet.lang.diagnostics.Errors.AUTOCAST_IMPOSSIBLE; import static org.jetbrains.jet.lang.diagnostics.Errors.SMARTCAST_IMPOSSIBLE;
import static org.jetbrains.jet.lang.resolve.BindingContext.AUTOCAST;
import static org.jetbrains.jet.lang.resolve.BindingContext.EXPRESSION_TYPE; import static org.jetbrains.jet.lang.resolve.BindingContext.EXPRESSION_TYPE;
import static org.jetbrains.jet.lang.resolve.BindingContext.SMARTCAST;
public class AutoCastUtils { public class SmartCastUtils {
private AutoCastUtils() {} private SmartCastUtils() {}
@NotNull @NotNull
public static List<JetType> getAutoCastVariants( public static List<JetType> getSmartCastVariants(
@NotNull ReceiverValue receiverToCast, @NotNull ReceiverValue receiverToCast,
@NotNull ResolutionContext context @NotNull ResolutionContext context
) { ) {
return getAutoCastVariants(receiverToCast, context.trace.getBindingContext(), context.dataFlowInfo); return getSmartCastVariants(receiverToCast, context.trace.getBindingContext(), context.dataFlowInfo);
} }
@NotNull @NotNull
public static List<JetType> getAutoCastVariants( public static List<JetType> getSmartCastVariants(
@NotNull ReceiverValue receiverToCast, @NotNull ReceiverValue receiverToCast,
@NotNull BindingContext bindingContext, @NotNull BindingContext bindingContext,
@NotNull DataFlowInfo dataFlowInfo @NotNull DataFlowInfo dataFlowInfo
) { ) {
List<JetType> variants = Lists.newArrayList(); List<JetType> variants = Lists.newArrayList();
variants.add(receiverToCast.getType()); variants.add(receiverToCast.getType());
variants.addAll(getAutoCastVariantsExcludingReceiver(bindingContext, dataFlowInfo, receiverToCast)); variants.addAll(getSmartCastVariantsExcludingReceiver(bindingContext, dataFlowInfo, receiverToCast));
return variants; return variants;
} }
@@ -68,7 +68,7 @@ public class AutoCastUtils {
* @return variants @param receiverToCast may be cast to according to @param dataFlowInfo, @param receiverToCast itself is NOT included * @return variants @param receiverToCast may be cast to according to @param dataFlowInfo, @param receiverToCast itself is NOT included
*/ */
@NotNull @NotNull
public static List<JetType> getAutoCastVariantsExcludingReceiver( public static List<JetType> getSmartCastVariantsExcludingReceiver(
@NotNull BindingContext bindingContext, @NotNull BindingContext bindingContext,
@NotNull DataFlowInfo dataFlowInfo, @NotNull DataFlowInfo dataFlowInfo,
@NotNull ReceiverValue receiverToCast @NotNull ReceiverValue receiverToCast
@@ -77,43 +77,43 @@ public class AutoCastUtils {
ThisReceiver receiver = (ThisReceiver) receiverToCast; ThisReceiver receiver = (ThisReceiver) receiverToCast;
assert receiver.exists(); assert receiver.exists();
DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(receiver); DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(receiver);
return collectAutoCastReceiverValues(dataFlowInfo, dataFlowValue); return collectSmartCastReceiverValues(dataFlowInfo, dataFlowValue);
} }
else if (receiverToCast instanceof ExpressionReceiver) { else if (receiverToCast instanceof ExpressionReceiver) {
ExpressionReceiver receiver = (ExpressionReceiver) receiverToCast; ExpressionReceiver receiver = (ExpressionReceiver) receiverToCast;
DataFlowValue dataFlowValue = DataFlowValue dataFlowValue =
DataFlowValueFactory.createDataFlowValue(receiver.getExpression(), receiver.getType(), bindingContext); DataFlowValueFactory.createDataFlowValue(receiver.getExpression(), receiver.getType(), bindingContext);
return collectAutoCastReceiverValues(dataFlowInfo, dataFlowValue); return collectSmartCastReceiverValues(dataFlowInfo, dataFlowValue);
} }
return Collections.emptyList(); return Collections.emptyList();
} }
@NotNull @NotNull
private static List<JetType> collectAutoCastReceiverValues( private static List<JetType> collectSmartCastReceiverValues(
@NotNull DataFlowInfo dataFlowInfo, @NotNull DataFlowInfo dataFlowInfo,
@NotNull DataFlowValue dataFlowValue @NotNull DataFlowValue dataFlowValue
) { ) {
return Lists.newArrayList(dataFlowInfo.getPossibleTypes(dataFlowValue)); return Lists.newArrayList(dataFlowInfo.getPossibleTypes(dataFlowValue));
} }
public static boolean isSubTypeByAutoCastIgnoringNullability( public static boolean isSubTypeBySmartCastIgnoringNullability(
@NotNull ReceiverValue receiverArgument, @NotNull ReceiverValue receiverArgument,
@NotNull JetType receiverParameterType, @NotNull JetType receiverParameterType,
@NotNull ResolutionContext context @NotNull ResolutionContext context
) { ) {
List<JetType> autoCastTypes = getAutoCastVariants(receiverArgument, context); List<JetType> smartCastTypes = getSmartCastVariants(receiverArgument, context);
return getAutoCastSubType(TypeUtils.makeNullable(receiverParameterType), autoCastTypes) != null; return getSmartCastSubType(TypeUtils.makeNullable(receiverParameterType), smartCastTypes) != null;
} }
@Nullable @Nullable
private static JetType getAutoCastSubType( private static JetType getSmartCastSubType(
@NotNull JetType receiverParameterType, @NotNull JetType receiverParameterType,
@NotNull List<JetType> autoCastTypes @NotNull List<JetType> smartCastTypes
) { ) {
Set<JetType> subTypes = Sets.newHashSet(); Set<JetType> subTypes = Sets.newHashSet();
for (JetType autoCastType : autoCastTypes) { for (JetType smartCastType : smartCastTypes) {
if (ArgumentTypeResolver.isSubtypeOfForArgumentType(autoCastType, receiverParameterType)) { if (ArgumentTypeResolver.isSubtypeOfForArgumentType(smartCastType, receiverParameterType)) {
subTypes.add(autoCastType); subTypes.add(smartCastType);
} }
} }
if (subTypes.isEmpty()) return null; if (subTypes.isEmpty()) return null;
@@ -125,7 +125,7 @@ public class AutoCastUtils {
return intersection; return intersection;
} }
public static boolean recordAutoCastIfNecessary( public static boolean recordSmartCastIfNecessary(
@NotNull ReceiverValue receiver, @NotNull ReceiverValue receiver,
@NotNull JetType receiverParameterType, @NotNull JetType receiverParameterType,
@NotNull ResolutionContext context, @NotNull ResolutionContext context,
@@ -138,15 +138,15 @@ public class AutoCastUtils {
return false; return false;
} }
List<JetType> autoCastTypesExcludingReceiver = getAutoCastVariantsExcludingReceiver( List<JetType> smartCastTypesExcludingReceiver = getSmartCastVariantsExcludingReceiver(
context.trace.getBindingContext(), context.dataFlowInfo, receiver); context.trace.getBindingContext(), context.dataFlowInfo, receiver);
JetType autoCastSubType = getAutoCastSubType(receiverParameterType, autoCastTypesExcludingReceiver); JetType smartCastSubType = getSmartCastSubType(receiverParameterType, smartCastTypesExcludingReceiver);
if (autoCastSubType == null) return false; if (smartCastSubType == null) return false;
JetExpression expression = ((ExpressionReceiver) receiver).getExpression(); JetExpression expression = ((ExpressionReceiver) receiver).getExpression();
DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(receiver, context.trace.getBindingContext()); DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(receiver, context.trace.getBindingContext());
recordCastOrError(expression, autoCastSubType, context.trace, dataFlowValue.isStableIdentifier(), true); recordCastOrError(expression, smartCastSubType, context.trace, dataFlowValue.isStableIdentifier(), true);
return true; return true;
} }
@@ -158,7 +158,7 @@ public class AutoCastUtils {
boolean recordExpressionType boolean recordExpressionType
) { ) {
if (canBeCasted) { if (canBeCasted) {
trace.record(AUTOCAST, expression, type); trace.record(SMARTCAST, expression, type);
if (recordExpressionType) { if (recordExpressionType) {
//TODO //TODO
//Why the expression type is rewritten for receivers and is not rewritten for arguments? Is it necessary? //Why the expression type is rewritten for receivers and is not rewritten for arguments? Is it necessary?
@@ -166,7 +166,7 @@ public class AutoCastUtils {
} }
} }
else { else {
trace.report(AUTOCAST_IMPOSSIBLE.on(expression, type, expression.getText())); trace.report(SMARTCAST_IMPOSSIBLE.on(expression, type, expression.getText()));
} }
} }
@@ -177,9 +177,9 @@ public class AutoCastUtils {
) { ) {
if (!receiver.getType().isNullable()) return true; if (!receiver.getType().isNullable()) return true;
List<JetType> autoCastVariants = getAutoCastVariants(receiver, bindingContext, dataFlowInfo); List<JetType> smartCastVariants = getSmartCastVariants(receiver, bindingContext, dataFlowInfo);
for (JetType autoCastVariant : autoCastVariants) { for (JetType smartCastVariant : smartCastVariants) {
if (!autoCastVariant.isNullable()) return true; if (!smartCastVariant.isNullable()) return true;
} }
return false; return false;
} }
@@ -24,10 +24,10 @@ import org.jetbrains.jet.lang.psi.Call;
import org.jetbrains.jet.lang.psi.JetReferenceExpression; import org.jetbrains.jet.lang.psi.JetReferenceExpression;
import org.jetbrains.jet.lang.resolve.BindingTrace; import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.calls.CallResolverExtension; import org.jetbrains.jet.lang.resolve.calls.CallResolverExtension;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.context.*; import org.jetbrains.jet.lang.resolve.calls.context.*;
import org.jetbrains.jet.lang.resolve.calls.model.MutableDataFlowInfoForArguments; import org.jetbrains.jet.lang.resolve.calls.model.MutableDataFlowInfoForArguments;
import org.jetbrains.jet.lang.resolve.calls.model.MutableResolvedCall; import org.jetbrains.jet.lang.resolve.calls.model.MutableResolvedCall;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
@@ -25,8 +25,8 @@ import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.psi.Call; import org.jetbrains.jet.lang.psi.Call;
import org.jetbrains.jet.lang.psi.JetExpression; import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.psi.JetSuperExpression; import org.jetbrains.jet.lang.psi.JetSuperExpression;
import org.jetbrains.jet.lang.resolve.calls.autocasts.AutoCastUtils;
import org.jetbrains.jet.lang.resolve.calls.context.BasicCallResolutionContext; import org.jetbrains.jet.lang.resolve.calls.context.BasicCallResolutionContext;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.SmartCastUtils;
import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.JetScopeUtils; import org.jetbrains.jet.lang.resolve.scopes.JetScopeUtils;
@@ -129,7 +129,7 @@ public class TaskPrioritizer {
boolean isExplicit boolean isExplicit
) { ) {
List<JetType> variantsForExplicitReceiver = AutoCastUtils.getAutoCastVariants(explicitReceiver, c.context); List<JetType> variantsForExplicitReceiver = SmartCastUtils.getSmartCastVariants(explicitReceiver, c.context);
//members //members
for (CallableDescriptorCollector<D> callableDescriptorCollector : c.callableDescriptorCollectors) { for (CallableDescriptorCollector<D> callableDescriptorCollector : c.callableDescriptorCollectors) {
@@ -319,7 +319,7 @@ public class TaskPrioritizer {
List<ReceiverParameterDescriptor> receivers = scope.getImplicitReceiversHierarchy(); List<ReceiverParameterDescriptor> receivers = scope.getImplicitReceiversHierarchy();
for (ReceiverParameterDescriptor receiver : receivers) { for (ReceiverParameterDescriptor receiver : receivers) {
if (JetTypeChecker.DEFAULT.isSubtypeOf(receiver.getType(), dispatchReceiver.getType())) { if (JetTypeChecker.DEFAULT.isSubtypeOf(receiver.getType(), dispatchReceiver.getType())) {
// TODO : Autocasts & nullability // TODO : Smartcasts & nullability
candidate.setDispatchReceiver(dispatchReceiver.getValue()); candidate.setDispatchReceiver(dispatchReceiver.getValue());
return true; return true;
} }
@@ -28,7 +28,7 @@ import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.AnnotationResolver; import org.jetbrains.jet.lang.resolve.AnnotationResolver;
import org.jetbrains.jet.lang.resolve.BindingTrace; import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.ScriptNameUtil; import org.jetbrains.jet.lang.resolve.ScriptNameUtil;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo; import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.lazy.ResolveSession; import org.jetbrains.jet.lang.resolve.lazy.ResolveSession;
import org.jetbrains.jet.lang.resolve.lazy.data.JetClassLikeInfo; import org.jetbrains.jet.lang.resolve.lazy.data.JetClassLikeInfo;
import org.jetbrains.jet.lang.resolve.lazy.data.JetScriptInfo; import org.jetbrains.jet.lang.resolve.lazy.data.JetScriptInfo;
@@ -18,7 +18,7 @@ package org.jetbrains.jet.lang.types;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo; import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
public class JetTypeInfo { public class JetTypeInfo {
@@ -33,10 +33,6 @@ import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.*; import org.jetbrains.jet.lang.resolve.*;
import org.jetbrains.jet.lang.resolve.calls.ArgumentTypeResolver; import org.jetbrains.jet.lang.resolve.calls.ArgumentTypeResolver;
import org.jetbrains.jet.lang.resolve.calls.CallExpressionResolver; import org.jetbrains.jet.lang.resolve.calls.CallExpressionResolver;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValue;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValueFactory;
import org.jetbrains.jet.lang.resolve.calls.autocasts.Nullability;
import org.jetbrains.jet.lang.resolve.calls.context.BasicCallResolutionContext; import org.jetbrains.jet.lang.resolve.calls.context.BasicCallResolutionContext;
import org.jetbrains.jet.lang.resolve.calls.context.CheckValueArgumentsMode; import org.jetbrains.jet.lang.resolve.calls.context.CheckValueArgumentsMode;
import org.jetbrains.jet.lang.resolve.calls.context.TemporaryTraceAndCache; import org.jetbrains.jet.lang.resolve.calls.context.TemporaryTraceAndCache;
@@ -47,6 +43,10 @@ import org.jetbrains.jet.lang.resolve.calls.model.VariableAsFunctionResolvedCall
import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults; import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults;
import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResultsImpl; import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResultsImpl;
import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResultsUtil; import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResultsUtil;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowValue;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowValueFactory;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.Nullability;
import org.jetbrains.jet.lang.resolve.calls.tasks.ExplicitReceiverKind; import org.jetbrains.jet.lang.resolve.calls.tasks.ExplicitReceiverKind;
import org.jetbrains.jet.lang.resolve.calls.tasks.ResolutionCandidate; import org.jetbrains.jet.lang.resolve.calls.tasks.ResolutionCandidate;
import org.jetbrains.jet.lang.resolve.calls.tasks.TracingStrategy; import org.jetbrains.jet.lang.resolve.calls.tasks.TracingStrategy;
@@ -972,9 +972,9 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
if (key == right && slice == EXPRESSION_TYPE) return false; if (key == right && slice == EXPRESSION_TYPE) return false;
// a hack due to KT-678 // a hack due to KT-678
// without this line an autocast is reported on the receiver (if it was previously checked for not-null) // without this line an smartcast is reported on the receiver (if it was previously checked for not-null)
// with not-null check the resolution result changes from 'fun Any?.equals' to 'equals' member // with not-null check the resolution result changes from 'fun Any?.equals' to 'equals' member
if (key == left && slice == AUTOCAST) return false; if (key == left && slice == SMARTCAST) return false;
return true; return true;
} }
@@ -32,11 +32,11 @@ import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContextUtils; import org.jetbrains.jet.lang.resolve.BindingContextUtils;
import org.jetbrains.jet.lang.resolve.BindingTrace; import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.calls.CallResolver; import org.jetbrains.jet.lang.resolve.calls.CallResolver;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.inference.*; import org.jetbrains.jet.lang.resolve.calls.inference.*;
import org.jetbrains.jet.lang.resolve.calls.model.MutableDataFlowInfoForArguments; import org.jetbrains.jet.lang.resolve.calls.model.MutableDataFlowInfoForArguments;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults; import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.tasks.ExplicitReceiverKind; import org.jetbrains.jet.lang.resolve.calls.tasks.ExplicitReceiverKind;
import org.jetbrains.jet.lang.resolve.calls.tasks.ResolutionCandidate; import org.jetbrains.jet.lang.resolve.calls.tasks.ResolutionCandidate;
import org.jetbrains.jet.lang.resolve.calls.tasks.TracingStrategy; import org.jetbrains.jet.lang.resolve.calls.tasks.TracingStrategy;
@@ -26,9 +26,9 @@ import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.diagnostics.Errors; import org.jetbrains.jet.lang.diagnostics.Errors;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.*; import org.jetbrains.jet.lang.resolve.*;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.model.MutableDataFlowInfoForArguments; import org.jetbrains.jet.lang.resolve.calls.model.MutableDataFlowInfoForArguments;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.WritableScope; import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl; import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
@@ -25,11 +25,11 @@ import org.jetbrains.jet.lang.evaluate.EvaluatePackage;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingTrace; import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.calls.autocasts.AutoCastUtils;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValue;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValueFactory;
import org.jetbrains.jet.lang.resolve.calls.context.ResolutionContext; import org.jetbrains.jet.lang.resolve.calls.context.ResolutionContext;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowValue;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowValueFactory;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.SmartCastUtils;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant; import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstantChecker; import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstantChecker;
import org.jetbrains.jet.lang.resolve.constants.IntegerValueTypeConstant; import org.jetbrains.jet.lang.resolve.constants.IntegerValueTypeConstant;
@@ -41,7 +41,6 @@ import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.lexer.JetTokens; import org.jetbrains.jet.lexer.JetTokens;
import static org.jetbrains.jet.lang.diagnostics.Errors.*; import static org.jetbrains.jet.lang.diagnostics.Errors.*;
import static org.jetbrains.jet.lang.resolve.calls.context.ContextDependency.DEPENDENT;
import static org.jetbrains.jet.lang.resolve.calls.context.ContextDependency.INDEPENDENT; import static org.jetbrains.jet.lang.resolve.calls.context.ContextDependency.INDEPENDENT;
import static org.jetbrains.jet.lang.types.TypeUtils.*; import static org.jetbrains.jet.lang.types.TypeUtils.*;
@@ -181,7 +180,7 @@ public class DataFlowUtils {
DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(expression, expressionType, trace.getBindingContext()); DataFlowValue dataFlowValue = DataFlowValueFactory.createDataFlowValue(expression, expressionType, trace.getBindingContext());
for (JetType possibleType : dataFlowInfo.getPossibleTypes(dataFlowValue)) { for (JetType possibleType : dataFlowInfo.getPossibleTypes(dataFlowValue)) {
if (JetTypeChecker.DEFAULT.isSubtypeOf(possibleType, expectedType)) { if (JetTypeChecker.DEFAULT.isSubtypeOf(possibleType, expectedType)) {
AutoCastUtils.recordCastOrError(expression, possibleType, trace, dataFlowValue.isStableIdentifier(), false); SmartCastUtils.recordCastOrError(expression, possibleType, trace, dataFlowValue.isStableIdentifier(), false);
return possibleType; return possibleType;
} }
} }
@@ -19,11 +19,11 @@ package org.jetbrains.jet.lang.types.expressions;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.resolve.BindingTrace; import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.calls.CallResolverExtension; import org.jetbrains.jet.lang.resolve.calls.CallResolverExtension;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.context.ContextDependency; import org.jetbrains.jet.lang.resolve.calls.context.ContextDependency;
import org.jetbrains.jet.lang.resolve.calls.context.ResolutionContext; import org.jetbrains.jet.lang.resolve.calls.context.ResolutionContext;
import org.jetbrains.jet.lang.resolve.calls.context.ResolutionResultsCache; import org.jetbrains.jet.lang.resolve.calls.context.ResolutionResultsCache;
import org.jetbrains.jet.lang.resolve.calls.context.ResolutionResultsCacheImpl; import org.jetbrains.jet.lang.resolve.calls.context.ResolutionResultsCacheImpl;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstantChecker; import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstantChecker;
import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.types.JetType; import org.jetbrains.jet.lang.types.JetType;
@@ -33,9 +33,9 @@ import org.jetbrains.jet.lang.resolve.calls.CallExpressionResolver;
import org.jetbrains.jet.lang.resolve.calls.CallResolver; import org.jetbrains.jet.lang.resolve.calls.CallResolver;
import org.jetbrains.jet.lang.resolve.calls.CallResolverExtension; import org.jetbrains.jet.lang.resolve.calls.CallResolverExtension;
import org.jetbrains.jet.lang.resolve.calls.CallResolverExtensionProvider; import org.jetbrains.jet.lang.resolve.calls.CallResolverExtensionProvider;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.context.ContextDependency; import org.jetbrains.jet.lang.resolve.calls.context.ContextDependency;
import org.jetbrains.jet.lang.resolve.calls.context.ResolutionContext; import org.jetbrains.jet.lang.resolve.calls.context.ResolutionContext;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.WritableScope; import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl; import org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl;
@@ -33,8 +33,6 @@ import org.jetbrains.jet.lang.diagnostics.Errors;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.*; import org.jetbrains.jet.lang.resolve.*;
import org.jetbrains.jet.lang.resolve.calls.CallResolver; import org.jetbrains.jet.lang.resolve.calls.CallResolver;
import org.jetbrains.jet.lang.resolve.calls.autocasts.AutoCastUtils;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.callUtil.CallUtilPackage; import org.jetbrains.jet.lang.resolve.calls.callUtil.CallUtilPackage;
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintPosition; import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintPosition;
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystem; import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystem;
@@ -42,6 +40,8 @@ import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemImpl;
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintsUtil; import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintsUtil;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults; import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.SmartCastUtils;
import org.jetbrains.jet.lang.resolve.calls.util.CallMaker; import org.jetbrains.jet.lang.resolve.calls.util.CallMaker;
import org.jetbrains.jet.lang.resolve.dataClassUtils.DataClassUtilsPackage; import org.jetbrains.jet.lang.resolve.dataClassUtils.DataClassUtilsPackage;
import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.resolve.name.Name;
@@ -203,7 +203,7 @@ public class ExpressionTypingUtils {
return false; return false;
} }
List<JetType> types = AutoCastUtils.getAutoCastVariants(receiverArgument, bindingContext, dataFlowInfo); List<JetType> types = SmartCastUtils.getSmartCastVariants(receiverArgument, bindingContext, dataFlowInfo);
for (JetType type : types) { for (JetType type : types) {
if (checkReceiverResolution(receiverArgument, type, callableDescriptor)) return true; if (checkReceiverResolution(receiverArgument, type, callableDescriptor)) return true;
@@ -27,11 +27,11 @@ import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
import org.jetbrains.jet.lang.diagnostics.Errors; import org.jetbrains.jet.lang.diagnostics.Errors;
import org.jetbrains.jet.lang.psi.*; import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.*; import org.jetbrains.jet.lang.resolve.*;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.context.TemporaryTraceAndCache; import org.jetbrains.jet.lang.resolve.calls.context.TemporaryTraceAndCache;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults; import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults;
import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResultsUtil; import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResultsUtil;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.WritableScope; import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
@@ -26,9 +26,9 @@ import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory1;
import org.jetbrains.jet.lang.psi.Call; import org.jetbrains.jet.lang.psi.Call;
import org.jetbrains.jet.lang.psi.JetExpression; import org.jetbrains.jet.lang.psi.JetExpression;
import org.jetbrains.jet.lang.resolve.BindingTraceContext; import org.jetbrains.jet.lang.resolve.BindingTraceContext;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall; import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults; import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults;
import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.name.Name; import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.resolve.scopes.JetScope; import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver; import org.jetbrains.jet.lang.resolve.scopes.receivers.ExpressionReceiver;
@@ -25,9 +25,9 @@ import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.jet.lang.resolve.BindingContext; import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.PossiblyBareType; import org.jetbrains.jet.lang.resolve.PossiblyBareType;
import org.jetbrains.jet.lang.resolve.TypeResolutionContext; import org.jetbrains.jet.lang.resolve.TypeResolutionContext;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo; import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowInfo;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValue; import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowValue;
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowValueFactory; import org.jetbrains.jet.lang.resolve.calls.smartcasts.DataFlowValueFactory;
import org.jetbrains.jet.lang.resolve.calls.util.CallMaker; import org.jetbrains.jet.lang.resolve.calls.util.CallMaker;
import org.jetbrains.jet.lang.resolve.scopes.WritableScope; import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
import org.jetbrains.jet.lang.types.*; import org.jetbrains.jet.lang.types.*;
@@ -310,7 +310,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
@NotNull JetType subjectType, @NotNull JetType subjectType,
@NotNull JetElement reportErrorOn @NotNull JetElement reportErrorOn
) { ) {
// TODO : Take auto casts into account? // TODO : Take smart casts into account?
if (type == null) { if (type == null) {
return; return;
} }
@@ -38,7 +38,7 @@ class C {
break; break;
} }
} }
<!DEBUG_INFO_AUTOCAST!>a<!>.compareTo("2") <!DEBUG_INFO_SMARTCAST!>a<!>.compareTo("2")
} }
fun containsBreakWithLabel(a: String?) { fun containsBreakWithLabel(a: String?) {
@@ -52,7 +52,7 @@ class C {
@loop while(a == null) { @loop while(a == null) {
<!NOT_A_LOOP_LABEL!>break<!UNRESOLVED_REFERENCE!>@label<!><!> <!NOT_A_LOOP_LABEL!>break<!UNRESOLVED_REFERENCE!>@label<!><!>
} }
<!DEBUG_INFO_AUTOCAST!>a<!>.compareTo("2") <!DEBUG_INFO_SMARTCAST!>a<!>.compareTo("2")
} }
fun containsBreakToOuterLoop(a: String?, b: String?) { fun containsBreakToOuterLoop(a: String?, b: String?) {
@@ -60,7 +60,7 @@ class C {
while(a == null) { while(a == null) {
break@loop break@loop
} }
<!DEBUG_INFO_AUTOCAST!>a<!>.compareTo("2") <!DEBUG_INFO_SMARTCAST!>a<!>.compareTo("2")
} }
} }
@@ -135,7 +135,7 @@ class A() : BodyTag("a") {
get() = attributes["href"] get() = attributes["href"]
set(value) { set(value) {
if (value != null) { if (value != null) {
attributes.put("href", <!DEBUG_INFO_AUTOCAST!>value<!>) attributes.put("href", <!DEBUG_INFO_SMARTCAST!>value<!>)
// attributes["href"] = value //doesn't work: KT-1355 // attributes["href"] = value //doesn't work: KT-1355
} }
} }
@@ -4,6 +4,6 @@ fun gg() {
val a: String? = "" val a: String? = ""
if (a != null) { if (a != null) {
ff(<!DEBUG_INFO_AUTOCAST!>a<!>) ff(<!DEBUG_INFO_SMARTCAST!>a<!>)
} }
} }
@@ -5,4 +5,4 @@ package java
val c : lang.Class<*>? = null val c : lang.Class<*>? = null
val <T> Array<T>?.length : Int get() = if (this != null) <!DEBUG_INFO_AUTOCAST!>this<!>.size else throw NullPointerException() val <T> Array<T>?.length : Int get() = if (this != null) <!DEBUG_INFO_SMARTCAST!>this<!>.size else throw NullPointerException()
@@ -1,7 +1,7 @@
fun test() { fun test() {
val a : Int? = 0 val a : Int? = 0
if (a != null) { if (a != null) {
<!DEBUG_INFO_AUTOCAST!>a<!>.plus(1) <!DEBUG_INFO_SMARTCAST!>a<!>.plus(1)
} }
else { else {
a?.plus(1) a?.plus(1)
@@ -14,54 +14,54 @@ fun test() {
ins?.read() ins?.read()
if (ins != null) { if (ins != null) {
<!DEBUG_INFO_AUTOCAST!>ins<!>.read() <!DEBUG_INFO_SMARTCAST!>ins<!>.read()
out?.println() out?.println()
if (out != null) { if (out != null) {
<!DEBUG_INFO_AUTOCAST!>ins<!>.read(); <!DEBUG_INFO_SMARTCAST!>ins<!>.read();
<!DEBUG_INFO_AUTOCAST!>out<!>.println(); <!DEBUG_INFO_SMARTCAST!>out<!>.println();
} }
} }
if (out != null && ins != null) { if (out != null && ins != null) {
<!DEBUG_INFO_AUTOCAST!>ins<!>.read(); <!DEBUG_INFO_SMARTCAST!>ins<!>.read();
<!DEBUG_INFO_AUTOCAST!>out<!>.println(); <!DEBUG_INFO_SMARTCAST!>out<!>.println();
} }
if (out == null) { if (out == null) {
out?.println() out?.println()
} else { } else {
<!DEBUG_INFO_AUTOCAST!>out<!>.println() <!DEBUG_INFO_SMARTCAST!>out<!>.println()
} }
if (out != null && ins != null || out != null) { if (out != null && ins != null || out != null) {
ins?.read(); ins?.read();
ins<!UNSAFE_CALL!>.<!>read(); ins<!UNSAFE_CALL!>.<!>read();
<!DEBUG_INFO_AUTOCAST!>out<!>.println(); <!DEBUG_INFO_SMARTCAST!>out<!>.println();
} }
if (out == null || <!DEBUG_INFO_AUTOCAST!>out<!>.println(0) == Unit) { if (out == null || <!DEBUG_INFO_SMARTCAST!>out<!>.println(0) == Unit) {
out?.println(1) out?.println(1)
out<!UNSAFE_CALL!>.<!>println(1) out<!UNSAFE_CALL!>.<!>println(1)
} }
else { else {
<!DEBUG_INFO_AUTOCAST!>out<!>.println(2) <!DEBUG_INFO_SMARTCAST!>out<!>.println(2)
} }
if (out != null && <!DEBUG_INFO_AUTOCAST!>out<!>.println() == Unit) { if (out != null && <!DEBUG_INFO_SMARTCAST!>out<!>.println() == Unit) {
<!DEBUG_INFO_AUTOCAST!>out<!>.println(); <!DEBUG_INFO_SMARTCAST!>out<!>.println();
} }
else { else {
out?.println(); out?.println();
} }
if (out == null || <!DEBUG_INFO_AUTOCAST!>out<!>.println() == Unit) { if (out == null || <!DEBUG_INFO_SMARTCAST!>out<!>.println() == Unit) {
out?.println(); out?.println();
} }
else { else {
<!DEBUG_INFO_AUTOCAST!>out<!>.println(); <!DEBUG_INFO_SMARTCAST!>out<!>.println();
} }
if (1 == 2 || out != null && <!DEBUG_INFO_AUTOCAST!>out<!>.println(1) == Unit) { if (1 == 2 || out != null && <!DEBUG_INFO_SMARTCAST!>out<!>.println(1) == Unit) {
out?.println(2); out?.println(2);
out<!UNSAFE_CALL!>.<!>println(2); out<!UNSAFE_CALL!>.<!>println(2);
} }
@@ -74,55 +74,55 @@ fun test() {
ins?.read() ins?.read()
if (ins != null) { if (ins != null) {
<!DEBUG_INFO_AUTOCAST!>ins<!>.read() <!DEBUG_INFO_SMARTCAST!>ins<!>.read()
out?.println() out?.println()
if (out != null) { if (out != null) {
<!DEBUG_INFO_AUTOCAST!>ins<!>.read(); <!DEBUG_INFO_SMARTCAST!>ins<!>.read();
<!DEBUG_INFO_AUTOCAST!>out<!>.println(); <!DEBUG_INFO_SMARTCAST!>out<!>.println();
} }
} }
if (out != null && ins != null) { if (out != null && ins != null) {
<!DEBUG_INFO_AUTOCAST!>ins<!>.read(); <!DEBUG_INFO_SMARTCAST!>ins<!>.read();
<!DEBUG_INFO_AUTOCAST!>out<!>.println(); <!DEBUG_INFO_SMARTCAST!>out<!>.println();
} }
if (out == null) { if (out == null) {
out?.println() out?.println()
} else { } else {
<!DEBUG_INFO_AUTOCAST!>out<!>.println() <!DEBUG_INFO_SMARTCAST!>out<!>.println()
} }
if (out != null && ins != null || out != null) { if (out != null && ins != null || out != null) {
ins?.read(); ins?.read();
<!DEBUG_INFO_AUTOCAST!>out<!>.println(); <!DEBUG_INFO_SMARTCAST!>out<!>.println();
} }
if (out == null || <!DEBUG_INFO_AUTOCAST!>out<!>.println(0) == Unit) { if (out == null || <!DEBUG_INFO_SMARTCAST!>out<!>.println(0) == Unit) {
out?.println(1) out?.println(1)
out<!UNSAFE_CALL!>.<!>println(1) out<!UNSAFE_CALL!>.<!>println(1)
} }
else { else {
<!DEBUG_INFO_AUTOCAST!>out<!>.println(2) <!DEBUG_INFO_SMARTCAST!>out<!>.println(2)
} }
if (out != null && <!DEBUG_INFO_AUTOCAST!>out<!>.println() == Unit) { if (out != null && <!DEBUG_INFO_SMARTCAST!>out<!>.println() == Unit) {
<!DEBUG_INFO_AUTOCAST!>out<!>.println(); <!DEBUG_INFO_SMARTCAST!>out<!>.println();
} }
else { else {
out?.println(); out?.println();
out<!UNSAFE_CALL!>.<!>println(); out<!UNSAFE_CALL!>.<!>println();
} }
if (out == null || <!DEBUG_INFO_AUTOCAST!>out<!>.println() == Unit) { if (out == null || <!DEBUG_INFO_SMARTCAST!>out<!>.println() == Unit) {
out?.println(); out?.println();
out<!UNSAFE_CALL!>.<!>println(); out<!UNSAFE_CALL!>.<!>println();
} }
else { else {
<!DEBUG_INFO_AUTOCAST!>out<!>.println(); <!DEBUG_INFO_SMARTCAST!>out<!>.println();
} }
if (1 == 2 || out != null && <!DEBUG_INFO_AUTOCAST!>out<!>.println(1) == Unit) { if (1 == 2 || out != null && <!DEBUG_INFO_SMARTCAST!>out<!>.println(1) == Unit) {
out?.println(2); out?.println(2);
out<!UNSAFE_CALL!>.<!>println(2); out<!UNSAFE_CALL!>.<!>println(2);
} }
@@ -133,12 +133,12 @@ fun test() {
if (1 > 2) { if (1 > 2) {
if (out == null) return; if (out == null) return;
<!DEBUG_INFO_AUTOCAST!>out<!>.println(); <!DEBUG_INFO_SMARTCAST!>out<!>.println();
} }
out?.println(); out?.println();
while (out != null) { while (out != null) {
<!DEBUG_INFO_AUTOCAST!>out<!>.println(); <!DEBUG_INFO_SMARTCAST!>out<!>.println();
} }
out?.println(); out?.println();
@@ -148,7 +148,7 @@ fun test() {
out2?.println(); out2?.println();
out2<!UNSAFE_CALL!>.<!>println(); out2<!UNSAFE_CALL!>.<!>println();
} }
<!DEBUG_INFO_AUTOCAST!>out2<!>.println() <!DEBUG_INFO_SMARTCAST!>out2<!>.println()
} }
@@ -157,7 +157,7 @@ fun f(out : String?) {
out?.get(0) out?.get(0)
out<!UNSAFE_CALL!>.<!>get(0) out<!UNSAFE_CALL!>.<!>get(0)
if (out != null) else return; if (out != null) else return;
<!DEBUG_INFO_AUTOCAST!>out<!>.get(0) <!DEBUG_INFO_SMARTCAST!>out<!>.get(0)
} }
fun f1(out : String?) { fun f1(out : String?) {
@@ -166,7 +166,7 @@ fun f1(out : String?) {
1 + 2 1 + 2
return; return;
} }
<!DEBUG_INFO_AUTOCAST!>out<!>.get(0) <!DEBUG_INFO_SMARTCAST!>out<!>.get(0)
} }
fun f2(out : String?) { fun f2(out : String?) {
@@ -175,7 +175,7 @@ fun f2(out : String?) {
1 + 2 1 + 2
return; return;
} }
<!DEBUG_INFO_AUTOCAST!>out<!>.get(0) <!DEBUG_INFO_SMARTCAST!>out<!>.get(0)
} }
fun f3(out : String?) { fun f3(out : String?) {
@@ -187,25 +187,25 @@ fun f3(out : String?) {
else { else {
1 + 2 1 + 2
} }
<!DEBUG_INFO_AUTOCAST!>out<!>.get(0) <!DEBUG_INFO_SMARTCAST!>out<!>.get(0)
} }
fun f4(s : String?) { fun f4(s : String?) {
s?.get(0) s?.get(0)
while (1 < 2 && s != null) { while (1 < 2 && s != null) {
<!DEBUG_INFO_AUTOCAST!>s<!>.get(0) <!DEBUG_INFO_SMARTCAST!>s<!>.get(0)
} }
s?.get(0) s?.get(0)
while (s == null || 1 < 2) { while (s == null || 1 < 2) {
s?.get(0) s?.get(0)
} }
<!DEBUG_INFO_AUTOCAST!>s<!>.get(0) <!DEBUG_INFO_SMARTCAST!>s<!>.get(0)
} }
fun f5(s : String?) { fun f5(s : String?) {
s?.get(0) s?.get(0)
while (1 < 2 && s != null) { while (1 < 2 && s != null) {
<!DEBUG_INFO_AUTOCAST!>s<!>.get(0) <!DEBUG_INFO_SMARTCAST!>s<!>.get(0)
} }
s?.get(0) s?.get(0)
while (s == null || 1 < 2) { while (s == null || 1 < 2) {
@@ -225,24 +225,24 @@ fun f6(s : String?) {
do { do {
s?.get(0) s?.get(0)
} while (s == null) } while (s == null)
<!DEBUG_INFO_AUTOCAST!>s<!>.get(0) <!DEBUG_INFO_SMARTCAST!>s<!>.get(0)
} }
fun f7(s : String?, t : String?) { fun f7(s : String?, t : String?) {
s?.get(0) s?.get(0)
if (!(s == null)) { if (!(s == null)) {
<!DEBUG_INFO_AUTOCAST!>s<!>.get(0) <!DEBUG_INFO_SMARTCAST!>s<!>.get(0)
} }
s?.get(0) s?.get(0)
if (!(s != null)) { if (!(s != null)) {
s?.get(0) s?.get(0)
} }
else { else {
<!DEBUG_INFO_AUTOCAST!>s<!>.get(0) <!DEBUG_INFO_SMARTCAST!>s<!>.get(0)
} }
s?.get(0) s?.get(0)
if (!!(s != null)) { if (!!(s != null)) {
<!DEBUG_INFO_AUTOCAST!>s<!>.get(0) <!DEBUG_INFO_SMARTCAST!>s<!>.get(0)
} }
else { else {
s?.get(0) s?.get(0)
@@ -250,8 +250,8 @@ fun f7(s : String?, t : String?) {
s?.get(0) s?.get(0)
t?.get(0) t?.get(0)
if (!(s == null || t == null)) { if (!(s == null || t == null)) {
<!DEBUG_INFO_AUTOCAST!>s<!>.get(0) <!DEBUG_INFO_SMARTCAST!>s<!>.get(0)
<!DEBUG_INFO_AUTOCAST!>t<!>.get(0) <!DEBUG_INFO_SMARTCAST!>t<!>.get(0)
} }
else { else {
s?.get(0) s?.get(0)
@@ -260,7 +260,7 @@ fun f7(s : String?, t : String?) {
s?.get(0) s?.get(0)
t?.get(0) t?.get(0)
if (!(s == null)) { if (!(s == null)) {
<!DEBUG_INFO_AUTOCAST!>s<!>.get(0) <!DEBUG_INFO_SMARTCAST!>s<!>.get(0)
t?.get(0) t?.get(0)
} }
else { else {
@@ -272,22 +272,22 @@ fun f7(s : String?, t : String?) {
fun f8(b : String?, a : String) { fun f8(b : String?, a : String) {
b?.get(0) b?.get(0)
if (b == a) { if (b == a) {
<!DEBUG_INFO_AUTOCAST!>b<!>.get(0); <!DEBUG_INFO_SMARTCAST!>b<!>.get(0);
} }
b?.get(0) b?.get(0)
if (a == b) { if (a == b) {
<!DEBUG_INFO_AUTOCAST!>b<!>.get(0) <!DEBUG_INFO_SMARTCAST!>b<!>.get(0)
} }
if (a != b) { if (a != b) {
b?.get(0) b?.get(0)
} }
else { else {
<!DEBUG_INFO_AUTOCAST!>b<!>.get(0) <!DEBUG_INFO_SMARTCAST!>b<!>.get(0)
} }
} }
fun f9(a : Int?) : Int { fun f9(a : Int?) : Int {
if (a != null) if (a != null)
return <!DEBUG_INFO_AUTOCAST!>a<!> return <!DEBUG_INFO_SMARTCAST!>a<!>
return 1 return 1
} }
@@ -5,6 +5,6 @@ trait MutableMap<K, V>: Map<K, V> {
fun p(p: Map<String, Int>) { fun p(p: Map<String, Int>) {
if (p is MutableMap<String, Int>) { if (p is MutableMap<String, Int>) {
<!DEBUG_INFO_AUTOCAST!>p<!>[""] = 1 <!DEBUG_INFO_SMARTCAST!>p<!>[""] = 1
} }
} }
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -DEBUG_INFO_AUTOCAST // !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST
trait Either<out A, out B> trait Either<out A, out B>
trait Left<out A>: Either<A, Nothing> { trait Left<out A>: Either<A, Nothing> {
val value: A val value: A
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -DEBUG_INFO_AUTOCAST // !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST
trait Either<out A, out B> trait Either<out A, out B>
trait Left<out A>: Either<A, Nothing> { trait Left<out A>: Either<A, Nothing> {
val value: A val value: A
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -DEBUG_INFO_AUTOCAST // !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST
trait Either<out A, out B> trait Either<out A, out B>
trait Left<out A>: Either<A, Nothing> { trait Left<out A>: Either<A, Nothing> {
val value: A val value: A
@@ -1,6 +1,6 @@
fun illegalWhenBlock(a: Any): Int { fun illegalWhenBlock(a: Any): Int {
when(a) { when(a) {
is Int -> return <!DEBUG_INFO_AUTOCAST!>a<!> is Int -> return <!DEBUG_INFO_SMARTCAST!>a<!>
is String -> return <!DEBUG_INFO_AUTOCAST!>a<!>.length is String -> return <!DEBUG_INFO_SMARTCAST!>a<!>.length
} }
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!> <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
@@ -11,6 +11,6 @@ fun test(c: Coll?) {
for (x in <!ITERATOR_MISSING!>c<!>) {} for (x in <!ITERATOR_MISSING!>c<!>) {}
if (c != null) { if (c != null) {
for(x in <!DEBUG_INFO_AUTOCAST!>c<!>) {} for(x in <!DEBUG_INFO_SMARTCAST!>c<!>) {}
} }
} }
@@ -2,6 +2,6 @@ class C(val f : () -> Unit)
fun test(e : Any) { fun test(e : Any) {
if (e is C) { if (e is C) {
(<!DEBUG_INFO_AUTOCAST!>e<!>.f)() (<!DEBUG_INFO_SMARTCAST!>e<!>.f)()
} }
} }
@@ -1,13 +1,13 @@
fun f1(s: String?) { fun f1(s: String?) {
if (s!! == ""); if (s!! == "");
<!DEBUG_INFO_AUTOCAST!>s<!> : String <!DEBUG_INFO_SMARTCAST!>s<!> : String
} }
fun f2(s: Number?) { fun f2(s: Number?) {
if (s is Int); if (s is Int);
<!TYPE_MISMATCH!>s<!> : Int <!TYPE_MISMATCH!>s<!> : Int
if (s as Int == 42); if (s as Int == 42);
<!DEBUG_INFO_AUTOCAST!>s<!> : Int <!DEBUG_INFO_SMARTCAST!>s<!> : Int
} }
fun f3(s: Number?) { fun f3(s: Number?) {
@@ -3,7 +3,7 @@ class BinOp(val operator : String) : Expr
fun test(e : Expr) { fun test(e : Expr) {
if (e is BinOp) { if (e is BinOp) {
when (<!DEBUG_INFO_AUTOCAST!>e<!>.operator) { when (<!DEBUG_INFO_SMARTCAST!>e<!>.operator) {
else -> <!UNUSED_EXPRESSION!>0<!> else -> <!UNUSED_EXPRESSION!>0<!>
} }
} }
@@ -4,7 +4,7 @@ fun test(x: Any, y: Int?) {
if (x !is String) return if (x !is String) return
if (y == null) return if (y == null) return
class Local: Base(<!DEBUG_INFO_AUTOCAST!>x<!>, <!DEBUG_INFO_AUTOCAST!>y<!>) { class Local: Base(<!DEBUG_INFO_SMARTCAST!>x<!>, <!DEBUG_INFO_SMARTCAST!>y<!>) {
} }
} }
@@ -1,8 +1,8 @@
fun test(x: Any) { fun test(x: Any) {
if (x !is String) return if (x !is String) return
class Local(s: String = <!DEBUG_INFO_AUTOCAST!>x<!>) { class Local(s: String = <!DEBUG_INFO_SMARTCAST!>x<!>) {
fun foo(s: String = <!DEBUG_INFO_AUTOCAST!>x<!>): String = s fun foo(s: String = <!DEBUG_INFO_SMARTCAST!>x<!>): String = s
} }
} }
@@ -9,8 +9,8 @@ fun test(del: Any?) {
if (del !is Del) return if (del !is Del) return
class Local { class Local {
val delegatedVal by df(<!DEBUG_INFO_AUTOCAST!>del<!>) val delegatedVal by df(<!DEBUG_INFO_SMARTCAST!>del<!>)
val delegatedVal1: Int by df(<!DEBUG_INFO_AUTOCAST!>del<!>) val delegatedVal1: Int by df(<!DEBUG_INFO_SMARTCAST!>del<!>)
} }
} }
@@ -5,7 +5,7 @@ trait D {
fun test(d: Any?) { fun test(d: Any?) {
if (d !is D) return if (d !is D) return
class Local : D by <!DEBUG_INFO_AUTOCAST!>d<!> { class Local : D by <!DEBUG_INFO_SMARTCAST!>d<!> {
} }
} }
@@ -7,12 +7,12 @@ fun test(d: Any?) {
class Local { class Local {
fun f() { fun f() {
<!DEBUG_INFO_AUTOCAST!>d<!>.foo() <!DEBUG_INFO_SMARTCAST!>d<!>.foo()
} }
fun f1() = <!DEBUG_INFO_AUTOCAST!>d<!>.foo() fun f1() = <!DEBUG_INFO_SMARTCAST!>d<!>.foo()
fun f2(): String = <!DEBUG_INFO_AUTOCAST!>d<!>.foo() fun f2(): String = <!DEBUG_INFO_SMARTCAST!>d<!>.foo()
} }
} }
@@ -6,8 +6,8 @@ fun test(x: Any) {
if (y !is String) return if (y !is String) return
class Local { class Local {
{ {
<!DEBUG_INFO_AUTOCAST!>x<!>.length <!DEBUG_INFO_SMARTCAST!>x<!>.length
<!DEBUG_INFO_AUTOCAST!>y<!>.length <!DEBUG_INFO_SMARTCAST!>y<!>.length
} }
} }
} }
@@ -1,10 +1,10 @@
// KT-338 Support autocasts in nested declarations // KT-338 Support.smartcasts in nested declarations
fun f(a: Any?) { fun f(a: Any?) {
if (a is B) { if (a is B) {
class C : X(<!DEBUG_INFO_AUTOCAST!>a<!>) { class C : X(<!DEBUG_INFO_SMARTCAST!>a<!>) {
{ {
<!DEBUG_INFO_AUTOCAST!>a<!>.foo() <!DEBUG_INFO_SMARTCAST!>a<!>.foo()
} }
} }
} }
@@ -2,11 +2,11 @@ fun test(x: Any?) {
if (x !is String) return if (x !is String) return
class C { class C {
val v = <!DEBUG_INFO_AUTOCAST!>x<!>.length val v = <!DEBUG_INFO_SMARTCAST!>x<!>.length
val vGet: Int val vGet: Int
get() = <!DEBUG_INFO_AUTOCAST!>x<!>.length get() = <!DEBUG_INFO_SMARTCAST!>x<!>.length
val s: String = <!DEBUG_INFO_AUTOCAST!>x<!> val s: String = <!DEBUG_INFO_SMARTCAST!>x<!>
} }
} }
@@ -1,7 +1,7 @@
fun foo(x: Any?) { fun foo(x: Any?) {
if (x is String) { if (x is String) {
object : Base(<!DEBUG_INFO_AUTOCAST!>x<!>) { object : Base(<!DEBUG_INFO_SMARTCAST!>x<!>) {
fun bar() = <!DEBUG_INFO_AUTOCAST!>x<!>.length fun bar() = <!DEBUG_INFO_SMARTCAST!>x<!>.length
} }
} }
} }
@@ -9,7 +9,7 @@ class B : A {
} }
fun foo(b: B?) : Int { fun foo(b: B?) : Int {
if (b == null) return 0 if (b == null) return 0
val o = object : A by <!DEBUG_INFO_AUTOCAST!>b<!> { //no info about b not null check val o = object : A by <!DEBUG_INFO_SMARTCAST!>b<!> { //no info about b not null check
} }
return o.foo() return o.foo()
} }
@@ -4,7 +4,7 @@ fun test(x: Any) {
class LocalOuter { class LocalOuter {
inner class Local { inner class Local {
{ {
<!DEBUG_INFO_AUTOCAST!>x<!>.length <!DEBUG_INFO_SMARTCAST!>x<!>.length
} }
} }
} }
@@ -2,7 +2,7 @@ open class X(val s: String)
fun f(a: String?) { fun f(a: String?) {
if (a != null) { if (a != null) {
object : X(<!DEBUG_INFO_AUTOCAST!>a<!>) { // Type mismatch: inferred type is jet.String? but jet.String was expected object : X(<!DEBUG_INFO_SMARTCAST!>a<!>) { // Type mismatch: inferred type is jet.String? but jet.String was expected
} }
} }
} }
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -DEBUG_INFO_AUTOCAST // !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST
fun bar(x: Int): Int = x + 1 fun bar(x: Int): Int = x + 1
fun foo() { fun foo() {
@@ -4,10 +4,10 @@ fun foo() {
val x: Int? = null val x: Int? = null
val a = Array<Int>(3, {0}) val a = Array<Int>(3, {0})
if (x != null) bar(a[<!DEBUG_INFO_AUTOCAST!>x<!>]) else bar(a[<!TYPE_MISMATCH!>x<!>]) if (x != null) bar(a[<!DEBUG_INFO_SMARTCAST!>x<!>]) else bar(a[<!TYPE_MISMATCH!>x<!>])
bar(a[if (x == null) 0 else <!DEBUG_INFO_AUTOCAST!>x<!>]) bar(a[if (x == null) 0 else <!DEBUG_INFO_SMARTCAST!>x<!>])
bar(a[<!TYPE_MISMATCH!>x<!>]) bar(a[<!TYPE_MISMATCH!>x<!>])
"123"[<!TYPE_MISMATCH!>x<!>]; "123"[<!TYPE_MISMATCH!>x<!>];
if (x != null) "123"[<!DEBUG_INFO_AUTOCAST!>x<!>]; if (x != null) "123"[<!DEBUG_INFO_SMARTCAST!>x<!>];
} }
@@ -1,5 +1,5 @@
fun foo(arr: Array<out Number>): Int { fun foo(arr: Array<out Number>): Int {
val result = (arr as Array<Int>)[0] val result = (arr as Array<Int>)[0]
<!DEBUG_INFO_AUTOCAST!>arr<!> : Array<Int> <!DEBUG_INFO_SMARTCAST!>arr<!> : Array<Int>
return result return result
} }
@@ -4,23 +4,23 @@ trait G {
} }
fun foo1(a: Int?, b: G) { fun foo1(a: Int?, b: G) {
b[a!!, a<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>] = <!DEBUG_INFO_AUTOCAST!>a<!> b[a!!, a<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>] = <!DEBUG_INFO_SMARTCAST!>a<!>
<!DEBUG_INFO_AUTOCAST!>a<!> : Int <!DEBUG_INFO_SMARTCAST!>a<!> : Int
} }
fun foo2(a: Int?, b: G) { fun foo2(a: Int?, b: G) {
b[0, a!!] = <!DEBUG_INFO_AUTOCAST!>a<!> b[0, a!!] = <!DEBUG_INFO_SMARTCAST!>a<!>
<!DEBUG_INFO_AUTOCAST!>a<!> : Int <!DEBUG_INFO_SMARTCAST!>a<!> : Int
} }
fun foo3(a: Int?, b: G) { fun foo3(a: Int?, b: G) {
val r = b[a!!, <!DEBUG_INFO_AUTOCAST!>a<!>] val r = b[a!!, <!DEBUG_INFO_SMARTCAST!>a<!>]
<!DEBUG_INFO_AUTOCAST!>a<!> : Int <!DEBUG_INFO_SMARTCAST!>a<!> : Int
r : Int r : Int
} }
fun foo4(a: Int?, b: G) { fun foo4(a: Int?, b: G) {
val r = b[0, a!!] val r = b[0, a!!]
<!DEBUG_INFO_AUTOCAST!>a<!> : Int <!DEBUG_INFO_SMARTCAST!>a<!> : Int
r : Int r : Int
} }
@@ -1,9 +1,9 @@
fun foo1(a: Int?, b: Array<Array<Int>>) { fun foo1(a: Int?, b: Array<Array<Int>>) {
b[a!!][a<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>] = <!DEBUG_INFO_AUTOCAST!>a<!> b[a!!][a<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>] = <!DEBUG_INFO_SMARTCAST!>a<!>
<!DEBUG_INFO_AUTOCAST!>a<!> : Int <!DEBUG_INFO_SMARTCAST!>a<!> : Int
} }
fun foo2(a: Int?, b: Array<Array<Int>>) { fun foo2(a: Int?, b: Array<Array<Int>>) {
b[0][a!!] = <!DEBUG_INFO_AUTOCAST!>a<!> b[0][a!!] = <!DEBUG_INFO_SMARTCAST!>a<!>
<!DEBUG_INFO_AUTOCAST!>a<!> : Int <!DEBUG_INFO_SMARTCAST!>a<!> : Int
} }
@@ -5,13 +5,13 @@ trait B : A {
fun bar1(a: A) { fun bar1(a: A) {
var b: B = a as B var b: B = a as B
<!DEBUG_INFO_AUTOCAST!>a<!>.foo() <!DEBUG_INFO_SMARTCAST!>a<!>.foo()
b.foo() b.foo()
} }
fun id(b: B) = b fun id(b: B) = b
fun bar2(a: A) { fun bar2(a: A) {
var b: B = id(a as B) var b: B = id(a as B)
<!DEBUG_INFO_AUTOCAST!>a<!>.foo() <!DEBUG_INFO_SMARTCAST!>a<!>.foo()
b.foo() b.foo()
} }
@@ -10,12 +10,12 @@ fun baz(b: B) = b
fun bar1(a: A) { fun bar1(a: A) {
val b = a as B val b = a as B
<!DEBUG_INFO_AUTOCAST!>a<!>.foo() <!DEBUG_INFO_SMARTCAST!>a<!>.foo()
b.foo() b.foo()
} }
fun bar2(a: A) { fun bar2(a: A) {
val b = baz(a as B) val b = baz(a as B)
<!DEBUG_INFO_AUTOCAST!>a<!>.foo() <!DEBUG_INFO_SMARTCAST!>a<!>.foo()
b.foo() b.foo()
} }
@@ -1,15 +1,15 @@
fun bar1(x: Number, y: Int) { fun bar1(x: Number, y: Int) {
var yy = y var yy = y
yy += x as Int yy += x as Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int <!DEBUG_INFO_SMARTCAST!>x<!> : Int
} }
fun bar2(x: Number) { fun bar2(x: Number) {
<!UNRESOLVED_REFERENCE!>y<!> <!UNRESOLVED_REFERENCE!>+=<!> x as Int <!UNRESOLVED_REFERENCE!>y<!> <!UNRESOLVED_REFERENCE!>+=<!> x as Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int <!DEBUG_INFO_SMARTCAST!>x<!> : Int
} }
fun bar3(x: Number, y: Array<Int>) { fun bar3(x: Number, y: Array<Int>) {
y[0] += x as Int y[0] += x as Int
<!DEBUG_INFO_AUTOCAST!>x<!> : Int <!DEBUG_INFO_SMARTCAST!>x<!> : Int
} }
@@ -1,10 +1,10 @@
fun arrayAccessRHS(a: Int?, b: Array<Int>) { fun arrayAccessRHS(a: Int?, b: Array<Int>) {
b[0] = a!! b[0] = a!!
<!DEBUG_INFO_AUTOCAST!>a<!> : Int <!DEBUG_INFO_SMARTCAST!>a<!> : Int
} }
fun arrayAccessLHS(a: Int?, b: Array<Int>) { fun arrayAccessLHS(a: Int?, b: Array<Int>) {
b[a!!] = <!DEBUG_INFO_AUTOCAST!>a<!> b[a!!] = <!DEBUG_INFO_SMARTCAST!>a<!>
<!DEBUG_INFO_AUTOCAST!>a<!> : Int <!DEBUG_INFO_SMARTCAST!>a<!> : Int
} }
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -DEBUG_INFO_AUTOCAST // !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST
fun bar(x: Int): Int = x + 1 fun bar(x: Int): Int = x + 1
fun foo() { fun foo() {
@@ -6,7 +6,7 @@ fun foo1(x: Number, cond: Boolean): Boolean {
fun foo2(x: Number, cond: Boolean): Boolean { fun foo2(x: Number, cond: Boolean): Boolean {
val result = ((x as Int) == 42) && cond val result = ((x as Int) == 42) && cond
<!DEBUG_INFO_AUTOCAST!>x<!> : Int <!DEBUG_INFO_SMARTCAST!>x<!> : Int
return result return result
} }
@@ -18,6 +18,6 @@ fun foo3(x: Number, cond: Boolean): Boolean {
fun foo4(x: Number, cond: Boolean): Boolean { fun foo4(x: Number, cond: Boolean): Boolean {
val result = ((x as Int) == 42) || cond val result = ((x as Int) == 42) || cond
<!DEBUG_INFO_AUTOCAST!>x<!> : Int <!DEBUG_INFO_SMARTCAST!>x<!> : Int
return result return result
} }
@@ -4,13 +4,13 @@ trait B : A
fun B.compareTo(b: B) = if (this == b) 0 else 1 fun B.compareTo(b: B) = if (this == b) 0 else 1
fun foo(a: A): Boolean { fun foo(a: A): Boolean {
val result = (a as B) < <!DEBUG_INFO_AUTOCAST!>a<!> val result = (a as B) < <!DEBUG_INFO_SMARTCAST!>a<!>
<!DEBUG_INFO_AUTOCAST!>a<!> : B <!DEBUG_INFO_SMARTCAST!>a<!> : B
return result return result
} }
fun bar(a: A, b: B): Boolean { fun bar(a: A, b: B): Boolean {
val result = b < (a as B) val result = b < (a as B)
<!DEBUG_INFO_AUTOCAST!>a<!> : B <!DEBUG_INFO_SMARTCAST!>a<!> : B
return result return result
} }
@@ -1,5 +1,5 @@
fun foo(x: Number): Boolean { fun foo(x: Number): Boolean {
val result = (x as Int) in 1..5 val result = (x as Int) in 1..5
<!DEBUG_INFO_AUTOCAST!>x<!> : Int <!DEBUG_INFO_SMARTCAST!>x<!> : Int
return result return result
} }
@@ -1,8 +1,8 @@
fun foo(x: Int?): Int = x!! fun foo(x: Int?): Int = x!!
fun elvis(x: Number?): Int { fun elvis(x: Number?): Int {
val result = (x as Int?) ?: foo(<!DEBUG_INFO_AUTOCAST!>x<!>) val result = (x as Int?) ?: foo(<!DEBUG_INFO_SMARTCAST!>x<!>)
<!DEBUG_INFO_AUTOCAST!>x<!> : Int? <!DEBUG_INFO_SMARTCAST!>x<!> : Int?
return result return result
} }
@@ -3,12 +3,12 @@ trait B : A
fun foo1(a: A, b: B): Boolean { fun foo1(a: A, b: B): Boolean {
val result = (a as B) == b val result = (a as B) == b
<!DEBUG_INFO_AUTOCAST!>a<!> : B <!DEBUG_INFO_SMARTCAST!>a<!> : B
return result return result
} }
fun foo2(a: A, b: B): Boolean { fun foo2(a: A, b: B): Boolean {
val result = b == (a as B) val result = b == (a as B)
<!DEBUG_INFO_AUTOCAST!>a<!> : B <!DEBUG_INFO_SMARTCAST!>a<!> : B
return result return result
} }
@@ -1,11 +1,11 @@
fun foo(a: Number): Int { fun foo(a: Number): Int {
val result = (a as Int) compareTo <!DEBUG_INFO_AUTOCAST!>a<!> val result = (a as Int) compareTo <!DEBUG_INFO_SMARTCAST!>a<!>
<!DEBUG_INFO_AUTOCAST!>a<!> : Int <!DEBUG_INFO_SMARTCAST!>a<!> : Int
return result return result
} }
fun bar(a: Number): Int { fun bar(a: Number): Int {
val result = 42 compareTo (a as Int) val result = 42 compareTo (a as Int)
<!DEBUG_INFO_AUTOCAST!>a<!> : Int <!DEBUG_INFO_SMARTCAST!>a<!> : Int
return result return result
} }
@@ -4,13 +4,13 @@ trait B : A
fun B.plus(b: B) = if (this == b) b else this fun B.plus(b: B) = if (this == b) b else this
fun foo(a: A): B { fun foo(a: A): B {
val result = (a as B) + <!DEBUG_INFO_AUTOCAST!>a<!> val result = (a as B) + <!DEBUG_INFO_SMARTCAST!>a<!>
<!DEBUG_INFO_AUTOCAST!>a<!> : B <!DEBUG_INFO_SMARTCAST!>a<!> : B
return result return result
} }
fun bar(a: A, b: B): B { fun bar(a: A, b: B): B {
val result = b + (a as B) val result = b + (a as B)
<!DEBUG_INFO_AUTOCAST!>a<!> : B <!DEBUG_INFO_SMARTCAST!>a<!> : B
return result return result
} }
@@ -1,5 +1,5 @@
fun foo(x: Int?): Boolean { fun foo(x: Int?): Boolean {
val result = ((x!! == 0) && ((<!DEBUG_INFO_AUTOCAST!>x<!> : Int) == 0)) val result = ((x!! == 0) && ((<!DEBUG_INFO_SMARTCAST!>x<!> : Int) == 0))
<!DEBUG_INFO_AUTOCAST!>x<!> : Int <!DEBUG_INFO_SMARTCAST!>x<!> : Int
return result return result
} }
@@ -5,7 +5,7 @@ fun whileLoop(x: Int?) {
} }
<!TYPE_MISMATCH!>x<!> : Int <!TYPE_MISMATCH!>x<!> : Int
} }
<!DEBUG_INFO_AUTOCAST!>x<!> : Int <!DEBUG_INFO_SMARTCAST!>x<!> : Int
} }
fun doWhileLoop(x: Int?) { fun doWhileLoop(x: Int?) {
@@ -15,7 +15,7 @@ fun doWhileLoop(x: Int?) {
} while (x == null) } while (x == null)
<!TYPE_MISMATCH!>x<!> : Int <!TYPE_MISMATCH!>x<!> : Int
} }
<!DEBUG_INFO_AUTOCAST!>x<!> : Int <!DEBUG_INFO_SMARTCAST!>x<!> : Int
} }
fun whileLoopContinueInnerOuter(x: Int?) { fun whileLoopContinueInnerOuter(x: Int?) {
@@ -26,7 +26,7 @@ fun whileLoopContinueInnerOuter(x: Int?) {
} }
<!TYPE_MISMATCH!>x<!> : Int <!TYPE_MISMATCH!>x<!> : Int
} }
<!DEBUG_INFO_AUTOCAST!>x<!> : Int <!DEBUG_INFO_SMARTCAST!>x<!> : Int
} }
<!DEBUG_INFO_AUTOCAST!>x<!> : Int <!DEBUG_INFO_SMARTCAST!>x<!> : Int
} }
@@ -1,4 +1,4 @@
// !DIAGNOSTICS: -DEBUG_INFO_AUTOCAST // !DIAGNOSTICS: -DEBUG_INFO_SMARTCAST
fun bar(x: Int) = x + 1 fun bar(x: Int) = x + 1
fun foo() { fun foo() {
@@ -6,7 +6,7 @@ fun foo() {
do { do {
bar(<!TYPE_MISMATCH!>x<!>) bar(<!TYPE_MISMATCH!>x<!>)
} while (x == null) } while (x == null)
bar(<!DEBUG_INFO_AUTOCAST!>x<!>) bar(<!DEBUG_INFO_SMARTCAST!>x<!>)
val y: Int? = null val y: Int? = null
do { do {
@@ -4,7 +4,7 @@ fun simpleDoWhile(x: Int?, y0: Int) {
x : Int? x : Int?
y++ y++
} while (x!! == y) } while (x!! == y)
<!DEBUG_INFO_AUTOCAST!>x<!> : Int <!DEBUG_INFO_SMARTCAST!>x<!> : Int
} }
fun doWhileWithBreak(x: Int?, y0: Int) { fun doWhileWithBreak(x: Int?, y0: Int) {
@@ -4,6 +4,6 @@ fun foo() {
val x: Int? = null val x: Int? = null
bar(x ?: 0) bar(x ?: 0)
if (x != null) bar(<!USELESS_ELVIS!>x<!> ?: <!DEBUG_INFO_AUTOCAST!>x<!>) if (x != null) bar(<!USELESS_ELVIS!>x<!> ?: <!DEBUG_INFO_SMARTCAST!>x<!>)
bar(<!TYPE_MISMATCH!>x<!>) bar(<!TYPE_MISMATCH!>x<!>)
} }
@@ -1,5 +1,3 @@
import java.util.HashMap
fun bar(x: Int): Int = x + 1 fun bar(x: Int): Int = x + 1
fun foo() { fun foo() {
@@ -9,16 +7,16 @@ fun foo() {
for (p in a) { for (p in a) {
bar(<!TYPE_MISMATCH!>x<!>) bar(<!TYPE_MISMATCH!>x<!>)
if (x == null) continue if (x == null) continue
bar(<!DEBUG_INFO_AUTOCAST!>x<!>) bar(<!DEBUG_INFO_SMARTCAST!>x<!>)
for (q in a) { for (q in a) {
bar(<!DEBUG_INFO_AUTOCAST!>x<!>) bar(<!DEBUG_INFO_SMARTCAST!>x<!>)
if (<!SENSELESS_COMPARISON!>x == null<!>) bar(<!DEBUG_INFO_AUTOCAST!>x<!>) if (<!SENSELESS_COMPARISON!>x == null<!>) bar(<!DEBUG_INFO_SMARTCAST!>x<!>)
} }
} }
for (p in a) { for (p in a) {
bar(<!TYPE_MISMATCH!>x<!>) bar(<!TYPE_MISMATCH!>x<!>)
if (x == null) break if (x == null) break
bar(<!DEBUG_INFO_AUTOCAST!>x<!>) bar(<!DEBUG_INFO_SMARTCAST!>x<!>)
} }
} }
@@ -1,6 +1,6 @@
fun foo(arr: Array<Int>?) { fun foo(arr: Array<Int>?) {
for (x in arr!!) { for (x in arr!!) {
<!DEBUG_INFO_AUTOCAST!>arr<!> : Array<Int> <!DEBUG_INFO_SMARTCAST!>arr<!> : Array<Int>
} }
<!DEBUG_INFO_AUTOCAST!>arr<!> : Array<Int> <!DEBUG_INFO_SMARTCAST!>arr<!> : Array<Int>
} }
@@ -4,6 +4,6 @@ fun foo() {
val x: Int? = null val x: Int? = null
fun baz() = bar(<!TYPE_MISMATCH!>x<!>) fun baz() = bar(<!TYPE_MISMATCH!>x<!>)
fun quux() = if (x != null) bar(<!DEBUG_INFO_AUTOCAST!>x<!>) else baz() fun quux() = if (x != null) bar(<!DEBUG_INFO_SMARTCAST!>x<!>) else baz()
fun quuux() = bar(if (x == null) 0 else <!DEBUG_INFO_AUTOCAST!>x<!>) fun quuux() = bar(if (x == null) 0 else <!DEBUG_INFO_SMARTCAST!>x<!>)
} }
@@ -1,24 +1,24 @@
fun ifThen(x: Int?) { fun ifThen(x: Int?) {
if (x!! == 0) { if (x!! == 0) {
<!DEBUG_INFO_AUTOCAST!>x<!> : Int <!DEBUG_INFO_SMARTCAST!>x<!> : Int
} }
<!DEBUG_INFO_AUTOCAST!>x<!> : Int <!DEBUG_INFO_SMARTCAST!>x<!> : Int
} }
fun ifElse(x: Int?) { fun ifElse(x: Int?) {
if (x!! == 0) else { if (x!! == 0) else {
<!DEBUG_INFO_AUTOCAST!>x<!> : Int <!DEBUG_INFO_SMARTCAST!>x<!> : Int
} }
<!DEBUG_INFO_AUTOCAST!>x<!> : Int <!DEBUG_INFO_SMARTCAST!>x<!> : Int
} }
fun ifThenElse(x: Int?) { fun ifThenElse(x: Int?) {
if (x!! == 0) { if (x!! == 0) {
<!DEBUG_INFO_AUTOCAST!>x<!> : Int <!DEBUG_INFO_SMARTCAST!>x<!> : Int
} else { } else {
<!DEBUG_INFO_AUTOCAST!>x<!> : Int <!DEBUG_INFO_SMARTCAST!>x<!> : Int
} }
<!DEBUG_INFO_AUTOCAST!>x<!> : Int <!DEBUG_INFO_SMARTCAST!>x<!> : Int
} }
fun ifIs(x: Int?, cond: Boolean) { fun ifIs(x: Int?, cond: Boolean) {
@@ -3,27 +3,27 @@ fun bar(x: Int): Int = x + 1
fun foo() { fun foo() {
val x: Int? = null val x: Int? = null
bar(if (x == null) 0 else <!DEBUG_INFO_AUTOCAST!>x<!>) bar(if (x == null) 0 else <!DEBUG_INFO_SMARTCAST!>x<!>)
if (x == null) { if (x == null) {
bar(<!TYPE_MISMATCH!>x<!>) bar(<!TYPE_MISMATCH!>x<!>)
return return
} else { } else {
bar(<!DEBUG_INFO_AUTOCAST!>x<!>) bar(<!DEBUG_INFO_SMARTCAST!>x<!>)
} }
bar(<!DEBUG_INFO_AUTOCAST!>x<!>) bar(<!DEBUG_INFO_SMARTCAST!>x<!>)
val y: Int? = null val y: Int? = null
if (y is Int) { if (y is Int) {
bar(<!DEBUG_INFO_AUTOCAST!>y<!>) bar(<!DEBUG_INFO_SMARTCAST!>y<!>)
} else { } else {
bar(<!TYPE_MISMATCH!>y<!>) bar(<!TYPE_MISMATCH!>y<!>)
return return
} }
bar(<!DEBUG_INFO_AUTOCAST!>y<!>) bar(<!DEBUG_INFO_SMARTCAST!>y<!>)
val z: Int? = null val z: Int? = null
if (z != null) bar(<!DEBUG_INFO_AUTOCAST!>z<!>) if (z != null) bar(<!DEBUG_INFO_SMARTCAST!>z<!>)
bar(<!TYPE_MISMATCH!>z<!>) bar(<!TYPE_MISMATCH!>z<!>)
bar(z!!) bar(z!!)
if (<!SENSELESS_COMPARISON!>z != null<!>) bar(z<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>) if (<!SENSELESS_COMPARISON!>z != null<!>) bar(z<!UNNECESSARY_NOT_NULL_ASSERTION!>!!<!>)

Some files were not shown because too many files have changed in this diff Show More