[NI] Strip only Exact-annotation preserving others during inference

This commit is contained in:
Mikhail Zarechenskiy
2019-04-18 14:41:24 +03:00
parent 3f08753f87
commit 8f8e33f251
4 changed files with 13 additions and 2 deletions
@@ -45,8 +45,8 @@ abstract class AbstractTypeCheckerContextForConstraintSystem : AbstractTypeCheck
val hasExact = subType.isTypeVariableWithExact() || superType.isTypeVariableWithExact() val hasExact = subType.isTypeVariableWithExact() || superType.isTypeVariableWithExact()
// we should strip annotation's because we have incorporation operation and they should be not affected // we should strip annotation's because we have incorporation operation and they should be not affected
val mySubType = if (hasExact) subType.removeAnnotations() else subType val mySubType = if (hasExact) subType.removeExactAnnotation() else subType
val mySuperType = if (hasExact) superType.removeAnnotations() else superType val mySuperType = if (hasExact) superType.removeExactAnnotation() else superType
val result = internalAddSubtypeConstraint(mySubType, mySuperType) val result = internalAddSubtypeConstraint(mySubType, mySuperType)
if (!hasExact) return result if (!hasExact) return result
@@ -28,6 +28,8 @@ fun KotlinType.hasNoInferAnnotation(): Boolean = annotations.hasAnnotation(NO_IN
fun KotlinType.hasExactAnnotation(): Boolean = annotations.hasAnnotation(EXACT_ANNOTATION_FQ_NAME) fun KotlinType.hasExactAnnotation(): Boolean = annotations.hasAnnotation(EXACT_ANNOTATION_FQ_NAME)
fun AnnotationDescriptor.isExactAnnotation(): Boolean = this.fqName == EXACT_ANNOTATION_FQ_NAME
fun Annotations.hasInternalAnnotationForResolve(): Boolean = fun Annotations.hasInternalAnnotationForResolve(): Boolean =
hasAnnotation(NO_INFER_ANNOTATION_FQ_NAME) || hasAnnotation(EXACT_ANNOTATION_FQ_NAME) hasAnnotation(NO_INFER_ANNOTATION_FQ_NAME) || hasAnnotation(EXACT_ANNOTATION_FQ_NAME)
@@ -8,11 +8,13 @@ package org.jetbrains.kotlin.types.checker
import org.jetbrains.kotlin.builtins.KotlinBuiltIns import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.builtins.KotlinBuiltIns.FQ_NAMES import org.jetbrains.kotlin.builtins.KotlinBuiltIns.FQ_NAMES
import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.resolve.calls.inference.CapturedType import org.jetbrains.kotlin.resolve.calls.inference.CapturedType
import org.jetbrains.kotlin.resolve.descriptorUtil.hasExactAnnotation import org.jetbrains.kotlin.resolve.descriptorUtil.hasExactAnnotation
import org.jetbrains.kotlin.resolve.descriptorUtil.hasNoInferAnnotation import org.jetbrains.kotlin.resolve.descriptorUtil.hasNoInferAnnotation
import org.jetbrains.kotlin.resolve.constants.IntegerLiteralTypeConstructor import org.jetbrains.kotlin.resolve.constants.IntegerLiteralTypeConstructor
import org.jetbrains.kotlin.resolve.descriptorUtil.isExactAnnotation
import org.jetbrains.kotlin.types.* import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.model.* import org.jetbrains.kotlin.types.model.*
import org.jetbrains.kotlin.types.model.CaptureStatus import org.jetbrains.kotlin.types.model.CaptureStatus
@@ -343,6 +345,12 @@ interface ClassicTypeSystemContext : TypeSystemInferenceExtensionContext {
return this.replaceAnnotations(Annotations.EMPTY) return this.replaceAnnotations(Annotations.EMPTY)
} }
override fun KotlinTypeMarker.removeExactAnnotation(): KotlinTypeMarker {
require(this is UnwrappedType, this::errorMessage)
val annotationsWithoutExact = this.annotations.filterNot(AnnotationDescriptor::isExactAnnotation)
return this.replaceAnnotations(Annotations.create(annotationsWithoutExact))
}
override fun KotlinTypeMarker.hasExactAnnotation(): Boolean { override fun KotlinTypeMarker.hasExactAnnotation(): Boolean {
require(this is UnwrappedType, this::errorMessage) require(this is UnwrappedType, this::errorMessage)
return hasExactInternal(this) return hasExactInternal(this)
@@ -107,6 +107,7 @@ interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBui
fun KotlinTypeMarker.removeAnnotations(): KotlinTypeMarker fun KotlinTypeMarker.removeAnnotations(): KotlinTypeMarker
fun KotlinTypeMarker.removeExactAnnotation(): KotlinTypeMarker
fun SimpleTypeMarker.replaceArguments(newArguments: List<TypeArgumentMarker>): SimpleTypeMarker fun SimpleTypeMarker.replaceArguments(newArguments: List<TypeArgumentMarker>): SimpleTypeMarker