diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java index 3a0d4179e7b..9c6aa83ba62 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java @@ -198,7 +198,7 @@ public class JetControlFlowProcessor { } 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); } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/WhenChecker.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/WhenChecker.java index 157080d43f5..9b69b5ed710 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/WhenChecker.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/WhenChecker.java @@ -115,7 +115,7 @@ public final class WhenChecker { JetType type = trace.getBindingContext().get( EXPRESSION_TYPE, ((JetWhenConditionWithExpression) condition).getExpression() ); - if (type != null && KotlinBuiltIns.getInstance().isNothingOrNullableNothing(type)) { + if (type != null && KotlinBuiltIns.isNothingOrNullableNothing(type)) { return true; } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/JetControlFlowInstructionsGenerator.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/JetControlFlowInstructionsGenerator.java index 1c7dfeeb3c6..6fc964aa022 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/JetControlFlowInstructionsGenerator.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/JetControlFlowInstructionsGenerator.java @@ -486,7 +486,7 @@ public class JetControlFlowInstructionsGenerator extends JetControlFlowBuilderAd resolvedCall, receiverValues, arguments, - returnType != null && KotlinBuiltIns.getInstance().isNothing(returnType) ? null : valueFactory + returnType != null && KotlinBuiltIns.isNothing(returnType) ? null : valueFactory ); add(instruction); return instruction; diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java index 0154bfeb9ba..cab6787ace6 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java @@ -736,12 +736,12 @@ public class DescriptorResolver { @NotNull TypeParameterDescriptor parameter, @NotNull JetTypeParameter typeParameter ) { - if (KotlinBuiltIns.getInstance().isNothing(parameter.getUpperBoundsAsType())) { + if (KotlinBuiltIns.isNothing(parameter.getUpperBoundsAsType())) { trace.report(CONFLICTING_UPPER_BOUNDS.on(typeParameter, parameter)); } 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)); } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ReifiedTypeParameterSubstitutionCheck.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ReifiedTypeParameterSubstitutionCheck.java index 7668e3a1f63..2714ba31b73 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ReifiedTypeParameterSubstitutionCheck.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/ReifiedTypeParameterSubstitutionCheck.java @@ -50,7 +50,7 @@ public class ReifiedTypeParameterSubstitutionCheck implements CallResolverExtens 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)); } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/CastDiagnosticsUtil.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/CastDiagnosticsUtil.java index 6057c4472b7..164eb32114a 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/CastDiagnosticsUtil.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/CastDiagnosticsUtil.java @@ -43,7 +43,7 @@ public class CastDiagnosticsUtil { @NotNull JetType rhsType, @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; // 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 diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/SubstitutionUtils.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/SubstitutionUtils.java index 5504530a8f5..f8d77fbba48 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/SubstitutionUtils.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/SubstitutionUtils.java @@ -91,7 +91,7 @@ public class SubstitutionUtils { fullSubstitution.put(parameter.getTypeConstructor(), substitute); } } - if (KotlinBuiltIns.getInstance().isNothingOrNullableNothing(context)) return; + if (KotlinBuiltIns.isNothingOrNullableNothing(context)) return; for (JetType supertype : context.getConstructor().getSupertypes()) { fillInDeepSubstitutor(supertype, substitutor, substitution, fullSubstitution); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java index 947b25617a6..54e41c2f42a 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/BasicExpressionTypingVisitor.java @@ -1079,7 +1079,7 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { JetType rightType = rightTypeInfo.getType(); 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()); dataFlowInfo = dataFlowInfo.disequate(value, DataFlowValue.NULL); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingVisitor.java index 4b6c4f4b804..c24c0704253 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/ControlStructureTypingVisitor.java @@ -130,8 +130,8 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { DataFlowInfo thenDataFlowInfo = thenTypeInfo.getDataFlowInfo(); DataFlowInfo elseDataFlowInfo = elseTypeInfo.getDataFlowInfo(); - boolean jumpInThen = thenType != null && KotlinBuiltIns.getInstance().isNothing(thenType); - boolean jumpInElse = elseType != null && KotlinBuiltIns.getInstance().isNothing(elseType); + boolean jumpInThen = thenType != null && KotlinBuiltIns.isNothing(thenType); + boolean jumpInElse = elseType != null && KotlinBuiltIns.isNothing(elseType); DataFlowInfo resultDataFlowInfo; if (thenType == null && elseType == null) { @@ -167,7 +167,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor { presentScope, Collections.singletonList(presentBranch), CoercionStrategy.NO_COERCION, newContext, context.trace); JetType type = typeInfo.getType(); DataFlowInfo dataFlowInfo; - if (type != null && KotlinBuiltIns.getInstance().isNothing(type)) { + if (type != null && KotlinBuiltIns.isNothing(type)) { dataFlowInfo = otherInfo; } else { dataFlowInfo = typeInfo.getDataFlowInfo().or(otherInfo); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/PatternMatchingTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/PatternMatchingTypingVisitor.java index f98a244b6f0..6bd255f498c 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/PatternMatchingTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/PatternMatchingTypingVisitor.java @@ -325,7 +325,7 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor { } // 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)); } } diff --git a/core/descriptors/src/org/jetbrains/jet/lang/types/CommonSupertypes.java b/core/descriptors/src/org/jetbrains/jet/lang/types/CommonSupertypes.java index 457d9f35532..51a1e5b995b 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/types/CommonSupertypes.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/types/CommonSupertypes.java @@ -118,7 +118,7 @@ public class CommonSupertypes { JetType type = iterator.next(); assert type != null; assert !TypesPackage.isFlexible(type) : "Flexible type " + type + " passed to commonSuperTypeForInflexible"; - if (KotlinBuiltIns.getInstance().isNothingOrNullableNothing(type)) { + if (KotlinBuiltIns.isNothingOrNullableNothing(type)) { iterator.remove(); } if (type.isError()) { diff --git a/core/descriptors/src/org/jetbrains/jet/lang/types/TypeSubstitutor.java b/core/descriptors/src/org/jetbrains/jet/lang/types/TypeSubstitutor.java index 54c2358ee56..85960433d0c 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/types/TypeSubstitutor.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/types/TypeSubstitutor.java @@ -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()); diff --git a/core/descriptors/src/org/jetbrains/jet/lang/types/TypeUtils.java b/core/descriptors/src/org/jetbrains/jet/lang/types/TypeUtils.java index 67ba5be0b5f..ba8ab89cb7c 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/types/TypeUtils.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/types/TypeUtils.java @@ -171,7 +171,7 @@ public class TypeUtils { boolean nothingTypePresent = false; List nullabilityStripped = new ArrayList(types.size()); for (JetType type : types) { - nothingTypePresent |= KotlinBuiltIns.getInstance().isNothingOrNullableNothing(type); + nothingTypePresent |= KotlinBuiltIns.isNothingOrNullableNothing(type); allNullable &= type.isNullable(); nullabilityStripped.add(makeNotNullable(type)); } diff --git a/core/descriptors/src/org/jetbrains/jet/lang/types/checker/TypeCheckingProcedure.java b/core/descriptors/src/org/jetbrains/jet/lang/types/checker/TypeCheckingProcedure.java index b8df692fdd5..993b1816c36 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/types/checker/TypeCheckingProcedure.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/types/checker/TypeCheckingProcedure.java @@ -194,7 +194,7 @@ public class TypeCheckingProcedure { } subtype = TypeUtils.makeNotNullable(subtype); supertype = TypeUtils.makeNotNullable(supertype); - if (KotlinBuiltIns.getInstance().isNothingOrNullableNothing(subtype)) { + if (KotlinBuiltIns.isNothingOrNullableNothing(subtype)) { return true; } @Nullable JetType closestSupertype = findCorrespondingSupertype(subtype, supertype, constraints); diff --git a/core/descriptors/src/org/jetbrains/jet/lang/types/lang/KotlinBuiltIns.java b/core/descriptors/src/org/jetbrains/jet/lang/types/lang/KotlinBuiltIns.java index e675f6b3c55..89a9c4204da 100644 --- a/core/descriptors/src/org/jetbrains/jet/lang/types/lang/KotlinBuiltIns.java +++ b/core/descriptors/src/org/jetbrains/jet/lang/types/lang/KotlinBuiltIns.java @@ -835,18 +835,19 @@ public class KotlinBuiltIns { return FQ_NAMES.any.equals(DescriptorUtils.getFqName(descriptor)); } - public boolean isNothing(@NotNull JetType type) { + public static boolean isNothing(@NotNull JetType type) { return isNothingOrNullableNothing(type) && !type.isNullable(); } - public boolean isNullableNothing(@NotNull JetType type) { + public static boolean isNullableNothing(@NotNull JetType type) { return isNothingOrNullableNothing(type) && type.isNullable(); } - public boolean isNothingOrNullableNothing(@NotNull JetType type) { - return type.getConstructor() == getNothing().getTypeConstructor(); + public static boolean isNothingOrNullableNothing(@NotNull JetType type) { + ClassifierDescriptor descriptor = type.getConstructor().getDeclarationDescriptor(); + return descriptor != null && FQ_NAMES.nothing.equals(DescriptorUtils.getFqName(descriptor)); } public boolean isAnyOrNullableAny(@NotNull JetType type) { diff --git a/idea/src/org/jetbrains/jet/plugin/actions/internal/FindImplicitNothingAction.kt b/idea/src/org/jetbrains/jet/plugin/actions/internal/FindImplicitNothingAction.kt index 8eec92ea09d..4ee5fe05340 100644 --- a/idea/src/org/jetbrains/jet/plugin/actions/internal/FindImplicitNothingAction.kt +++ b/idea/src/org/jetbrains/jet/plugin/actions/internal/FindImplicitNothingAction.kt @@ -78,7 +78,7 @@ public class FindImplicitNothingAction : AnAction() { try { val bindingContext = resolutionFacade.analyze(expression) 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) } } @@ -126,9 +126,8 @@ public class FindImplicitNothingAction : AnAction() { } private fun JetType.isNothingOrNothingFunctionType(): Boolean { - val builtIns = KotlinBuiltIns.getInstance() return when { - builtIns.isNothing(this) -> true + KotlinBuiltIns.isNothing(this) -> true KotlinBuiltIns.isExactFunctionOrExtensionFunctionType(this) -> KotlinBuiltIns.getReturnTypeFromFunctionType(this).isNothingOrNothingFunctionType() diff --git a/idea/src/org/jetbrains/jet/plugin/completion/smart/TypesWithSmartCasts.kt b/idea/src/org/jetbrains/jet/plugin/completion/smart/TypesWithSmartCasts.kt index d7d9557026c..1988dd9dff4 100644 --- a/idea/src/org/jetbrains/jet/plugin/completion/smart/TypesWithSmartCasts.kt +++ b/idea/src/org/jetbrains/jet/plugin/completion/smart/TypesWithSmartCasts.kt @@ -46,7 +46,7 @@ class TypesWithSmartCasts(val bindingContext: BindingContext) { fun typesOf(descriptor: DeclarationDescriptor): Iterable { if (descriptor is CallableDescriptor) { 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? return listOf() } diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/ConvertToBlockBodyAction.kt b/idea/src/org/jetbrains/jet/plugin/intentions/ConvertToBlockBodyAction.kt index 476ee510c7f..2f9fa4d7bdb 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/ConvertToBlockBodyAction.kt +++ b/idea/src/org/jetbrains/jet/plugin/intentions/ConvertToBlockBodyAction.kt @@ -43,7 +43,7 @@ public class ConvertToBlockBodyAction : PsiElementBaseIntentionAction() { fun generateBody(returnsValue: Boolean): JetExpression { val bodyType = expressionType(body) 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 newBodyText = if (needReturn) "return ${oldBodyText}" else oldBodyText @@ -57,7 +57,7 @@ public class ConvertToBlockBodyAction : PsiElementBaseIntentionAction() { 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() body.replace(newBody) diff --git a/idea/src/org/jetbrains/jet/plugin/intentions/ConvertToExpressionBodyAction.kt b/idea/src/org/jetbrains/jet/plugin/intentions/ConvertToExpressionBodyAction.kt index 118d22cfb5c..47a9b2a71ef 100644 --- a/idea/src/org/jetbrains/jet/plugin/intentions/ConvertToExpressionBodyAction.kt +++ b/idea/src/org/jetbrains/jet/plugin/intentions/ConvertToExpressionBodyAction.kt @@ -93,7 +93,7 @@ public class ConvertToExpressionBodyAction : PsiElementBaseIntentionAction() { val expressionType = expressionType(statement) if (expressionType != null && - (KotlinBuiltIns.getInstance().isUnit(expressionType) || KotlinBuiltIns.getInstance().isNothing(expressionType))) + (KotlinBuiltIns.getInstance().isUnit(expressionType) || KotlinBuiltIns.isNothing(expressionType))) Data(declaration, statement) else null diff --git a/idea/src/org/jetbrains/jet/plugin/refactoring/extractFunction/extractableAnalysisUtil.kt b/idea/src/org/jetbrains/jet/plugin/refactoring/extractFunction/extractableAnalysisUtil.kt index 4d212f2ff44..7af1fc024a3 100644 --- a/idea/src/org/jetbrains/jet/plugin/refactoring/extractFunction/extractableAnalysisUtil.kt +++ b/idea/src/org/jetbrains/jet/plugin/refactoring/extractFunction/extractableAnalysisUtil.kt @@ -159,7 +159,7 @@ private fun List.checkEquivalence(checkPsi: Boolean): B } 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(