Added 'NoInfer' and 'Exact' annotations

This commit is contained in:
Svetlana Isakova
2015-10-06 22:10:37 +03:00
parent 9b1030de2e
commit f2efd30a5d
9 changed files with 114 additions and 0 deletions
+14
View File
@@ -118,3 +118,17 @@ public annotation class HiddenDeclaration
@Retention(SOURCE)
@MustBeDocumented
private annotation class external
/**
* Specifies that the corresponding type should be ignored during type inference.
*/
@Target(TYPE)
@Retention(SOURCE)
internal annotation class NoInfer
/**
* Specifies that the constraint built for the type during type inference should be an equality one.
*/
@Target(TYPE)
@Retention(SOURCE)
internal annotation class Exact
@@ -17,8 +17,17 @@
package org.jetbrains.kotlin.resolve.descriptorUtil
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotated
import org.jetbrains.kotlin.name.FqName
private val HIDDEN_ANNOTATION_FQ_NAME = FqName("kotlin.HiddenDeclaration")
public fun DeclarationDescriptor.isAnnotatedAsHidden(): Boolean = annotations.findAnnotation(HIDDEN_ANNOTATION_FQ_NAME) != null
private val NO_INFER_ANNOTATION_FQ_NAME = FqName("kotlin.NoInfer")
public fun Annotated.hasNoInferAnnotation(): Boolean = annotations.findAnnotation(NO_INFER_ANNOTATION_FQ_NAME) != null
private val EXACT_ANNOTATION_FQ_NAME = FqName("kotlin.Exact")
public fun Annotated.hasExactAnnotation(): Boolean = annotations.findAnnotation(EXACT_ANNOTATION_FQ_NAME) != null
@@ -29,6 +29,8 @@ import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.Constrain
import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPositionKind
import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.ConstraintPositionKind.TYPE_BOUND_POSITION
import org.jetbrains.kotlin.resolve.calls.inference.constraintPosition.derivedFrom
import org.jetbrains.kotlin.resolve.descriptorUtil.hasNoInferAnnotation
import org.jetbrains.kotlin.resolve.descriptorUtil.hasExactAnnotation
import org.jetbrains.kotlin.resolve.scopes.JetScope
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.TypeUtils.DONT_CARE
@@ -286,6 +288,11 @@ public class ConstraintSystemImpl : ConstraintSystem {
if (isErrorOrSpecialType(subType, constraintPosition) || isErrorOrSpecialType(superType, constraintPosition)) return
if (subType == null || superType == null) return
if (subType.hasNoInferAnnotation() || superType.hasNoInferAnnotation()) return
if ((subType.hasExactAnnotation() || superType.hasExactAnnotation()) && (constraintKind != EQUAL)) {
return doAddConstraint(EQUAL, subType, superType, constraintContext, typeCheckingProcedure)
}
assert(!superType.isFunctionPlaceholder) {
"The type for " + constraintPosition + " shouldn't be a placeholder for function type"
}