isNothing() made static
This commit is contained in:
@@ -198,7 +198,7 @@ public class JetControlFlowProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
JetType type = trace.getBindingContext().get(BindingContext.EXPRESSION_TYPE, expression);
|
JetType type = trace.getBindingContext().get(BindingContext.EXPRESSION_TYPE, expression);
|
||||||
if (type != null && KotlinBuiltIns.getInstance().isNothing(type)) {
|
if (type != null && KotlinBuiltIns.isNothing(type)) {
|
||||||
builder.jumpToError(expression);
|
builder.jumpToError(expression);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ public final class WhenChecker {
|
|||||||
JetType type = trace.getBindingContext().get(
|
JetType type = trace.getBindingContext().get(
|
||||||
EXPRESSION_TYPE, ((JetWhenConditionWithExpression) condition).getExpression()
|
EXPRESSION_TYPE, ((JetWhenConditionWithExpression) condition).getExpression()
|
||||||
);
|
);
|
||||||
if (type != null && KotlinBuiltIns.getInstance().isNothingOrNullableNothing(type)) {
|
if (type != null && KotlinBuiltIns.isNothingOrNullableNothing(type)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -486,7 +486,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd
|
|||||||
resolvedCall,
|
resolvedCall,
|
||||||
receiverValues,
|
receiverValues,
|
||||||
arguments,
|
arguments,
|
||||||
returnType != null && KotlinBuiltIns.getInstance().isNothing(returnType) ? null : valueFactory
|
returnType != null && KotlinBuiltIns.isNothing(returnType) ? null : valueFactory
|
||||||
);
|
);
|
||||||
add(instruction);
|
add(instruction);
|
||||||
return instruction;
|
return instruction;
|
||||||
|
|||||||
@@ -736,12 +736,12 @@ public class DescriptorResolver {
|
|||||||
@NotNull TypeParameterDescriptor parameter,
|
@NotNull TypeParameterDescriptor parameter,
|
||||||
@NotNull JetTypeParameter typeParameter
|
@NotNull JetTypeParameter typeParameter
|
||||||
) {
|
) {
|
||||||
if (KotlinBuiltIns.getInstance().isNothing(parameter.getUpperBoundsAsType())) {
|
if (KotlinBuiltIns.isNothing(parameter.getUpperBoundsAsType())) {
|
||||||
trace.report(CONFLICTING_UPPER_BOUNDS.on(typeParameter, parameter));
|
trace.report(CONFLICTING_UPPER_BOUNDS.on(typeParameter, parameter));
|
||||||
}
|
}
|
||||||
|
|
||||||
JetType classObjectType = parameter.getClassObjectType();
|
JetType classObjectType = parameter.getClassObjectType();
|
||||||
if (classObjectType != null && KotlinBuiltIns.getInstance().isNothing(classObjectType)) {
|
if (classObjectType != null && KotlinBuiltIns.isNothing(classObjectType)) {
|
||||||
trace.report(CONFLICTING_CLASS_OBJECT_UPPER_BOUNDS.on(typeParameter, parameter));
|
trace.report(CONFLICTING_CLASS_OBJECT_UPPER_BOUNDS.on(typeParameter, parameter));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -50,7 +50,7 @@ public class ReifiedTypeParameterSubstitutionCheck implements CallResolverExtens
|
|||||||
Errors.TYPE_PARAMETER_AS_REIFIED.on(getCallElement(context), parameter)
|
Errors.TYPE_PARAMETER_AS_REIFIED.on(getCallElement(context), parameter)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
else if (KotlinBuiltIns.getInstance().isNothingOrNullableNothing(argument) || TypesPackage.isDynamic(argument)) {
|
else if (KotlinBuiltIns.isNothingOrNullableNothing(argument) || TypesPackage.isDynamic(argument)) {
|
||||||
context.trace.report(Errors.REIFIED_TYPE_FORBIDDEN_SUBSTITUTION.on(getCallElement(context), argument));
|
context.trace.report(Errors.REIFIED_TYPE_FORBIDDEN_SUBSTITUTION.on(getCallElement(context), argument));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public class CastDiagnosticsUtil {
|
|||||||
@NotNull JetType rhsType,
|
@NotNull JetType rhsType,
|
||||||
@NotNull PlatformToKotlinClassMap platformToKotlinClassMap
|
@NotNull PlatformToKotlinClassMap platformToKotlinClassMap
|
||||||
) {
|
) {
|
||||||
if (KotlinBuiltIns.getInstance().isNullableNothing(lhsType) && !TypeUtils.isNullableType(rhsType)) return false;
|
if (KotlinBuiltIns.isNullableNothing(lhsType) && !TypeUtils.isNullableType(rhsType)) return false;
|
||||||
if (isRelated(lhsType, rhsType, platformToKotlinClassMap)) return true;
|
if (isRelated(lhsType, rhsType, platformToKotlinClassMap)) return true;
|
||||||
// This is an oversimplification (which does not render the method incomplete):
|
// This is an oversimplification (which does not render the method incomplete):
|
||||||
// we consider any type parameter capable of taking any value, which may be made more precise if we considered bounds
|
// we consider any type parameter capable of taking any value, which may be made more precise if we considered bounds
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ public class SubstitutionUtils {
|
|||||||
fullSubstitution.put(parameter.getTypeConstructor(), substitute);
|
fullSubstitution.put(parameter.getTypeConstructor(), substitute);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (KotlinBuiltIns.getInstance().isNothingOrNullableNothing(context)) return;
|
if (KotlinBuiltIns.isNothingOrNullableNothing(context)) return;
|
||||||
for (JetType supertype : context.getConstructor().getSupertypes()) {
|
for (JetType supertype : context.getConstructor().getSupertypes()) {
|
||||||
fillInDeepSubstitutor(supertype, substitutor, substitution, fullSubstitution);
|
fillInDeepSubstitutor(supertype, substitutor, substitution, fullSubstitution);
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1079,7 +1079,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
JetType rightType = rightTypeInfo.getType();
|
JetType rightType = rightTypeInfo.getType();
|
||||||
|
|
||||||
DataFlowInfo dataFlowInfo = resolvedCall.getDataFlowInfoForArguments().getResultInfo();
|
DataFlowInfo dataFlowInfo = resolvedCall.getDataFlowInfoForArguments().getResultInfo();
|
||||||
if (leftType != null && rightType != null && KotlinBuiltIns.getInstance().isNothingOrNullableNothing(rightType) && !rightType.isNullable()) {
|
if (leftType != null && rightType != null && KotlinBuiltIns.isNothingOrNullableNothing(rightType) && !rightType.isNullable()) {
|
||||||
DataFlowValue value = createDataFlowValue(left, leftType, context.trace.getBindingContext());
|
DataFlowValue value = createDataFlowValue(left, leftType, context.trace.getBindingContext());
|
||||||
dataFlowInfo = dataFlowInfo.disequate(value, DataFlowValue.NULL);
|
dataFlowInfo = dataFlowInfo.disequate(value, DataFlowValue.NULL);
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -130,8 +130,8 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
DataFlowInfo thenDataFlowInfo = thenTypeInfo.getDataFlowInfo();
|
DataFlowInfo thenDataFlowInfo = thenTypeInfo.getDataFlowInfo();
|
||||||
DataFlowInfo elseDataFlowInfo = elseTypeInfo.getDataFlowInfo();
|
DataFlowInfo elseDataFlowInfo = elseTypeInfo.getDataFlowInfo();
|
||||||
|
|
||||||
boolean jumpInThen = thenType != null && KotlinBuiltIns.getInstance().isNothing(thenType);
|
boolean jumpInThen = thenType != null && KotlinBuiltIns.isNothing(thenType);
|
||||||
boolean jumpInElse = elseType != null && KotlinBuiltIns.getInstance().isNothing(elseType);
|
boolean jumpInElse = elseType != null && KotlinBuiltIns.isNothing(elseType);
|
||||||
|
|
||||||
DataFlowInfo resultDataFlowInfo;
|
DataFlowInfo resultDataFlowInfo;
|
||||||
if (thenType == null && elseType == null) {
|
if (thenType == null && elseType == null) {
|
||||||
@@ -167,7 +167,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
presentScope, Collections.singletonList(presentBranch), CoercionStrategy.NO_COERCION, newContext, context.trace);
|
presentScope, Collections.singletonList(presentBranch), CoercionStrategy.NO_COERCION, newContext, context.trace);
|
||||||
JetType type = typeInfo.getType();
|
JetType type = typeInfo.getType();
|
||||||
DataFlowInfo dataFlowInfo;
|
DataFlowInfo dataFlowInfo;
|
||||||
if (type != null && KotlinBuiltIns.getInstance().isNothing(type)) {
|
if (type != null && KotlinBuiltIns.isNothing(type)) {
|
||||||
dataFlowInfo = otherInfo;
|
dataFlowInfo = otherInfo;
|
||||||
} else {
|
} else {
|
||||||
dataFlowInfo = typeInfo.getDataFlowInfo().or(otherInfo);
|
dataFlowInfo = typeInfo.getDataFlowInfo().or(otherInfo);
|
||||||
|
|||||||
+1
-1
@@ -325,7 +325,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check if the pattern is essentially a 'null' expression
|
// check if the pattern is essentially a 'null' expression
|
||||||
if (KotlinBuiltIns.getInstance().isNullableNothing(type) && !TypeUtils.isNullableType(subjectType)) {
|
if (KotlinBuiltIns.isNullableNothing(type) && !TypeUtils.isNullableType(subjectType)) {
|
||||||
context.trace.report(SENSELESS_NULL_IN_WHEN.on(reportErrorOn));
|
context.trace.report(SENSELESS_NULL_IN_WHEN.on(reportErrorOn));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ public class CommonSupertypes {
|
|||||||
JetType type = iterator.next();
|
JetType type = iterator.next();
|
||||||
assert type != null;
|
assert type != null;
|
||||||
assert !TypesPackage.isFlexible(type) : "Flexible type " + type + " passed to commonSuperTypeForInflexible";
|
assert !TypesPackage.isFlexible(type) : "Flexible type " + type + " passed to commonSuperTypeForInflexible";
|
||||||
if (KotlinBuiltIns.getInstance().isNothingOrNullableNothing(type)) {
|
if (KotlinBuiltIns.isNothingOrNullableNothing(type)) {
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
}
|
}
|
||||||
if (type.isError()) {
|
if (type.isError()) {
|
||||||
|
|||||||
@@ -169,7 +169,7 @@ public class TypeSubstitutor {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (KotlinBuiltIns.getInstance().isNothing(type) || type.isError()) return originalProjection;
|
if (KotlinBuiltIns.isNothing(type) || type.isError()) return originalProjection;
|
||||||
|
|
||||||
TypeProjection replacement = substitution.get(type.getConstructor());
|
TypeProjection replacement = substitution.get(type.getConstructor());
|
||||||
|
|
||||||
|
|||||||
@@ -171,7 +171,7 @@ public class TypeUtils {
|
|||||||
boolean nothingTypePresent = false;
|
boolean nothingTypePresent = false;
|
||||||
List<JetType> nullabilityStripped = new ArrayList<JetType>(types.size());
|
List<JetType> nullabilityStripped = new ArrayList<JetType>(types.size());
|
||||||
for (JetType type : types) {
|
for (JetType type : types) {
|
||||||
nothingTypePresent |= KotlinBuiltIns.getInstance().isNothingOrNullableNothing(type);
|
nothingTypePresent |= KotlinBuiltIns.isNothingOrNullableNothing(type);
|
||||||
allNullable &= type.isNullable();
|
allNullable &= type.isNullable();
|
||||||
nullabilityStripped.add(makeNotNullable(type));
|
nullabilityStripped.add(makeNotNullable(type));
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -194,7 +194,7 @@ public class TypeCheckingProcedure {
|
|||||||
}
|
}
|
||||||
subtype = TypeUtils.makeNotNullable(subtype);
|
subtype = TypeUtils.makeNotNullable(subtype);
|
||||||
supertype = TypeUtils.makeNotNullable(supertype);
|
supertype = TypeUtils.makeNotNullable(supertype);
|
||||||
if (KotlinBuiltIns.getInstance().isNothingOrNullableNothing(subtype)) {
|
if (KotlinBuiltIns.isNothingOrNullableNothing(subtype)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@Nullable JetType closestSupertype = findCorrespondingSupertype(subtype, supertype, constraints);
|
@Nullable JetType closestSupertype = findCorrespondingSupertype(subtype, supertype, constraints);
|
||||||
|
|||||||
@@ -835,18 +835,19 @@ public class KotlinBuiltIns {
|
|||||||
return FQ_NAMES.any.equals(DescriptorUtils.getFqName(descriptor));
|
return FQ_NAMES.any.equals(DescriptorUtils.getFqName(descriptor));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isNothing(@NotNull JetType type) {
|
public static boolean isNothing(@NotNull JetType type) {
|
||||||
return isNothingOrNullableNothing(type)
|
return isNothingOrNullableNothing(type)
|
||||||
&& !type.isNullable();
|
&& !type.isNullable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isNullableNothing(@NotNull JetType type) {
|
public static boolean isNullableNothing(@NotNull JetType type) {
|
||||||
return isNothingOrNullableNothing(type)
|
return isNothingOrNullableNothing(type)
|
||||||
&& type.isNullable();
|
&& type.isNullable();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isNothingOrNullableNothing(@NotNull JetType type) {
|
public static boolean isNothingOrNullableNothing(@NotNull JetType type) {
|
||||||
return type.getConstructor() == getNothing().getTypeConstructor();
|
ClassifierDescriptor descriptor = type.getConstructor().getDeclarationDescriptor();
|
||||||
|
return descriptor != null && FQ_NAMES.nothing.equals(DescriptorUtils.getFqName(descriptor));
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAnyOrNullableAny(@NotNull JetType type) {
|
public boolean isAnyOrNullableAny(@NotNull JetType type) {
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ public class FindImplicitNothingAction : AnAction() {
|
|||||||
try {
|
try {
|
||||||
val bindingContext = resolutionFacade.analyze(expression)
|
val bindingContext = resolutionFacade.analyze(expression)
|
||||||
val type = bindingContext[BindingContext.EXPRESSION_TYPE, expression] ?: return
|
val type = bindingContext[BindingContext.EXPRESSION_TYPE, expression] ?: return
|
||||||
if (KotlinBuiltIns.getInstance().isNothing(type) && !expression.hasExplicitNothing(bindingContext)) { //TODO: what about nullable Nothing?
|
if (KotlinBuiltIns.isNothing(type) && !expression.hasExplicitNothing(bindingContext)) { //TODO: what about nullable Nothing?
|
||||||
found.add(expression)
|
found.add(expression)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -126,9 +126,8 @@ public class FindImplicitNothingAction : AnAction() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun JetType.isNothingOrNothingFunctionType(): Boolean {
|
private fun JetType.isNothingOrNothingFunctionType(): Boolean {
|
||||||
val builtIns = KotlinBuiltIns.getInstance()
|
|
||||||
return when {
|
return when {
|
||||||
builtIns.isNothing(this) -> true
|
KotlinBuiltIns.isNothing(this) -> true
|
||||||
|
|
||||||
KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(this) -> KotlinBuiltIns.getReturnTypeFromFunctionType(this).isNothingOrNothingFunctionType()
|
KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(this) -> KotlinBuiltIns.getReturnTypeFromFunctionType(this).isNothingOrNothingFunctionType()
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class TypesWithSmartCasts(val bindingContext: BindingContext) {
|
|||||||
fun typesOf(descriptor: DeclarationDescriptor): Iterable<JetType> {
|
fun typesOf(descriptor: DeclarationDescriptor): Iterable<JetType> {
|
||||||
if (descriptor is CallableDescriptor) {
|
if (descriptor is CallableDescriptor) {
|
||||||
var returnType = descriptor.getReturnType()
|
var returnType = descriptor.getReturnType()
|
||||||
if (returnType != null && KotlinBuiltIns.getInstance().isNothing(returnType!!)) {
|
if (returnType != null && KotlinBuiltIns.isNothing(returnType!!)) {
|
||||||
//TODO: maybe we should include them on the second press?
|
//TODO: maybe we should include them on the second press?
|
||||||
return listOf()
|
return listOf()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ public class ConvertToBlockBodyAction : PsiElementBaseIntentionAction() {
|
|||||||
fun generateBody(returnsValue: Boolean): JetExpression {
|
fun generateBody(returnsValue: Boolean): JetExpression {
|
||||||
val bodyType = expressionType(body)
|
val bodyType = expressionType(body)
|
||||||
val needReturn = returnsValue &&
|
val needReturn = returnsValue &&
|
||||||
(bodyType == null || (!KotlinBuiltIns.getInstance().isUnit(bodyType) && !KotlinBuiltIns.getInstance().isNothing(bodyType)))
|
(bodyType == null || (!KotlinBuiltIns.getInstance().isUnit(bodyType) && !KotlinBuiltIns.isNothing(bodyType)))
|
||||||
|
|
||||||
val oldBodyText = body.getText()!!
|
val oldBodyText = body.getText()!!
|
||||||
val newBodyText = if (needReturn) "return ${oldBodyText}" else oldBodyText
|
val newBodyText = if (needReturn) "return ${oldBodyText}" else oldBodyText
|
||||||
@@ -57,7 +57,7 @@ public class ConvertToBlockBodyAction : PsiElementBaseIntentionAction() {
|
|||||||
specifyTypeExplicitly(declaration, returnType)
|
specifyTypeExplicitly(declaration, returnType)
|
||||||
}
|
}
|
||||||
|
|
||||||
val newBody = generateBody(!KotlinBuiltIns.getInstance().isUnit(returnType) && !KotlinBuiltIns.getInstance().isNothing(returnType))
|
val newBody = generateBody(!KotlinBuiltIns.getInstance().isUnit(returnType) && !KotlinBuiltIns.isNothing(returnType))
|
||||||
|
|
||||||
declaration.getEqualsToken()!!.delete()
|
declaration.getEqualsToken()!!.delete()
|
||||||
body.replace(newBody)
|
body.replace(newBody)
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ public class ConvertToExpressionBodyAction : PsiElementBaseIntentionAction() {
|
|||||||
|
|
||||||
val expressionType = expressionType(statement)
|
val expressionType = expressionType(statement)
|
||||||
if (expressionType != null &&
|
if (expressionType != null &&
|
||||||
(KotlinBuiltIns.getInstance().isUnit(expressionType) || KotlinBuiltIns.getInstance().isNothing(expressionType)))
|
(KotlinBuiltIns.getInstance().isUnit(expressionType) || KotlinBuiltIns.isNothing(expressionType)))
|
||||||
Data(declaration, statement)
|
Data(declaration, statement)
|
||||||
else
|
else
|
||||||
null
|
null
|
||||||
|
|||||||
+1
-1
@@ -159,7 +159,7 @@ private fun List<AbstractJumpInstruction>.checkEquivalence(checkPsi: Boolean): B
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun JetType.isMeaningful(): Boolean {
|
private fun JetType.isMeaningful(): Boolean {
|
||||||
return KotlinBuiltIns.getInstance().let { builtins -> !builtins.isUnit(this) && !builtins.isNothing(this) }
|
return KotlinBuiltIns.getInstance().let { builtins -> !builtins.isUnit(this) && !KotlinBuiltIns.isNothing(this) }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun ExtractionData.getLocalDeclarationsWithNonLocalUsages(
|
private fun ExtractionData.getLocalDeclarationsWithNonLocalUsages(
|
||||||
|
|||||||
Reference in New Issue
Block a user