diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/AdditionalCheckerProvider.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/AdditionalCheckerProvider.kt index a92008ebdf0..e66791d2c5e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/AdditionalCheckerProvider.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/AdditionalCheckerProvider.kt @@ -22,7 +22,7 @@ import org.jetbrains.kotlin.resolve.validation.SymbolUsageValidator private val DEFAULT_DECLARATION_CHECKERS = listOf(DataClassAnnotationChecker()) private val DEFAULT_CALL_CHECKERS = listOf(CapturingInClosureChecker(), InlineCheckerWrapper(), ReifiedTypeParameterSubstitutionChecker()) -private val DEFAULT_TYPE_CHECKERS = listOf(TypeApproximator()) +private val DEFAULT_TYPE_CHECKERS = emptyList() private val DEFAULT_VALIDATORS = listOf(DeprecatedSymbolValidator()) public abstract class AdditionalCheckerProvider( diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContext.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContext.java index efd27e7c827..952e2938faf 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContext.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/BindingContext.java @@ -36,7 +36,6 @@ import org.jetbrains.kotlin.resolve.constants.CompileTimeConstant; import org.jetbrains.kotlin.resolve.diagnostics.Diagnostics; import org.jetbrains.kotlin.resolve.scopes.JetScope; import org.jetbrains.kotlin.resolve.scopes.receivers.Qualifier; -import org.jetbrains.kotlin.types.Approximation; import org.jetbrains.kotlin.types.DeferredType; import org.jetbrains.kotlin.types.JetType; import org.jetbrains.kotlin.types.expressions.CaptureKind; @@ -97,7 +96,6 @@ public interface BindingContext { WritableSlice EXPRESSION_TYPE_INFO = new BasicWritableSlice(DO_NOTHING); WritableSlice EXPECTED_EXPRESSION_TYPE = new BasicWritableSlice(DO_NOTHING); WritableSlice EXPECTED_RETURN_TYPE = new BasicWritableSlice(DO_NOTHING); - WritableSlice EXPRESSION_RESULT_APPROXIMATION = new BasicWritableSlice(DO_NOTHING); WritableSlice DATAFLOW_INFO_AFTER_CONDITION = Slices.createSimpleSlice(); /** diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/TypeApproximator.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/TypeApproximator.kt deleted file mode 100644 index f95f420b617..00000000000 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/TypeApproximator.kt +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.resolve.calls.checkers - -import org.jetbrains.kotlin.psi.JetExpression -import org.jetbrains.kotlin.types.JetType -import org.jetbrains.kotlin.resolve.calls.context.ResolutionContext - -import org.jetbrains.kotlin.types.TypeUtils.noExpectedType -import org.jetbrains.kotlin.types.getApproximationTo -import org.jetbrains.kotlin.types.Approximation -import org.jetbrains.kotlin.resolve.calls.smartcasts.DataFlowValueFactory -import com.intellij.openapi.util.text.StringUtil -import org.jetbrains.kotlin.resolve.BindingContext -import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor -import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue -import org.jetbrains.kotlin.resolve.calls.context.CallResolutionContext - -public class TypeApproximator : AdditionalTypeChecker { - override fun checkType(expression: JetExpression, expressionType: JetType, c: ResolutionContext<*>) { - if (noExpectedType(c.expectedType)) return - - val approximationInfo = expressionType.getApproximationTo( - c.expectedType, - object : Approximation.DataFlowExtras { - override val canBeNull: Boolean - get() = c.dataFlowInfo.getNullability(dataFlowValue).canBeNull() - override val possibleTypes: Set - get() = c.dataFlowInfo.getPossibleTypes(dataFlowValue) - override val presentableText: String - get() = StringUtil.trimMiddle(expression.getText(), 50) - - private val dataFlowValue = DataFlowValueFactory.createDataFlowValue(expression, expressionType, c) - } - ) - if (approximationInfo != null) { - c.trace.record(BindingContext.EXPRESSION_RESULT_APPROXIMATION, expression, approximationInfo) - } - } - - override fun checkReceiver( - receiverParameter: ReceiverParameterDescriptor, - receiverArgument: ReceiverValue, - safeAccess: Boolean, - c: CallResolutionContext<*> - ) { } -} \ No newline at end of file diff --git a/core/descriptors/src/org/jetbrains/kotlin/types/flexibleTypes.kt b/core/descriptors/src/org/jetbrains/kotlin/types/flexibleTypes.kt index 779346885a8..28834dd1aa8 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/types/flexibleTypes.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/types/flexibleTypes.kt @@ -105,38 +105,6 @@ public trait NullAwareness : TypeCapability { public fun computeIsNullable(): Boolean } -public trait Approximation : TypeCapability { - public class Info(val from: JetType, val to: JetType, val message: String) - public trait DataFlowExtras { - object EMPTY : DataFlowExtras { - override val canBeNull: Boolean get() = true - override val possibleTypes: Set get() = setOf() - override val presentableText: String = "" - } - - class OnlyMessage(message: String) : DataFlowExtras { - override val canBeNull: Boolean get() = true - override val possibleTypes: Set get() = setOf() - override val presentableText: String = message - } - - val canBeNull: Boolean - val possibleTypes: Set - val presentableText: String - } - - public fun approximateToExpectedType(expectedType: JetType, dataFlowExtras: DataFlowExtras): Info? -} - -fun Approximation.Info.assertNotNull(): Boolean { - return from.upperIfFlexible().isMarkedNullable() && !TypeUtils.isNullableType(to) -} - -public fun JetType.getApproximationTo( - expectedType: JetType, - extras: Approximation.DataFlowExtras = Approximation.DataFlowExtras.EMPTY -): Approximation.Info? = this.getCapability(javaClass())?.approximateToExpectedType(expectedType, extras) - trait FlexibleTypeDelegation : TypeCapability { public val delegateType: JetType } @@ -145,14 +113,13 @@ public open class DelegatingFlexibleType protected constructor( override val lowerBound: JetType, override val upperBound: JetType, override val extraCapabilities: FlexibleTypeCapabilities -) : DelegatingType(), NullAwareness, Flexibility, FlexibleTypeDelegation, Approximation { +) : DelegatingType(), NullAwareness, Flexibility, FlexibleTypeDelegation { companion object { internal val capabilityClasses = hashSetOf( javaClass(), javaClass(), javaClass(), - javaClass(), - javaClass() + javaClass() ) platformStatic fun create(lowerBound: JetType, upperBound: JetType, extraCapabilities: FlexibleTypeCapabilities): JetType { @@ -193,20 +160,6 @@ public open class DelegatingFlexibleType protected constructor( override fun isMarkedNullable(): Boolean = getCapability(javaClass())!!.computeIsNullable() - override fun approximateToExpectedType(expectedType: JetType, dataFlowExtras: Approximation.DataFlowExtras): Approximation.Info? { - // val foo: Any? = foo() : Foo! - if (JetTypeChecker.DEFAULT.isSubtypeOf(upperBound, expectedType)) return null - - // if (foo : Foo! != null) { - // val bar: Any = foo - // } - if (!dataFlowExtras.canBeNull && JetTypeChecker.DEFAULT.isSubtypeOf(TypeUtils.makeNotNullable(upperBound), expectedType)) return null - - // TODO: maybe check possibleTypes to avoid extra approximations - - return Approximation.Info(this, expectedType, dataFlowExtras.presentableText) - } - override val delegateType: JetType = lowerBound override fun getDelegate() = getCapability(javaClass())!!.delegateType