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
+8
View File
@@ -456,6 +456,10 @@ public abstract class Enum</*0*/ E : kotlin.Enum<E>> : kotlin.Comparable<E> {
}
}
@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.TYPE}) @kotlin.annotation.Retention(value = AnnotationRetention.SOURCE) @kotlin.annotation.annotation() internal final class Exact : kotlin.Annotation {
/*primary*/ public constructor Exact()
}
@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.TYPE}) @kotlin.annotation.MustBeDocumented() @kotlin.annotation.annotation() public final class Extension : kotlin.Annotation {
/*primary*/ public constructor Extension()
}
@@ -1040,6 +1044,10 @@ public interface MutableSet</*0*/ E> : kotlin.Set<E>, kotlin.MutableCollection<E
public abstract override /*1*/ fun retainAll(/*0*/ c: kotlin.Collection<kotlin.Any?>): kotlin.Boolean
}
@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.TYPE}) @kotlin.annotation.Retention(value = AnnotationRetention.SOURCE) @kotlin.annotation.annotation() internal final class NoInfer : kotlin.Annotation {
/*primary*/ public constructor NoInfer()
}
public final class Nothing {
/*primary*/ private constructor Nothing()
}
@@ -0,0 +1,11 @@
//!DIAGNOSTICS: -UNUSED_VARIABLE
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
fun <T, U: T> List<@Exact T>.firstTyped(): U = throw Exception()
fun test1(l: List<Number>) {
val i: Int = l.firstTyped()
val s: String = l.<!TYPE_INFERENCE_EXPECTED_TYPE_MISMATCH!>firstTyped<!>()
}
@@ -0,0 +1,4 @@
package
public fun test1(/*0*/ l: kotlin.List<kotlin.Number>): kotlin.Unit
@kotlin.Suppress(names = {"INVISIBLE_MEMBER", "INVISIBLE_REFERENCE"}) public fun </*0*/ T, /*1*/ U : T> kotlin.List<@kotlin.Exact() T>.firstTyped(): U
@@ -0,0 +1,30 @@
//!DIAGNOSTICS: -UNUSED_PARAMETER
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
fun <T> test1(t1: T, t2: @NoInfer T): T = t1
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
fun <T> @NoInfer T.test2(t1: T): T = t1
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
fun <T> test3(t1: @NoInfer T): T = t1
fun usage() {
test1(1, <!TYPE_MISMATCH!>"312"<!>)
<!TYPE_MISMATCH!>1<!>.test2("")
<!TYPE_INFERENCE_NO_INFORMATION_FOR_PARAMETER!>test3<!>("")
}
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
fun <T> List<T>.contains1(e: @NoInfer T): Boolean = true
fun test(l: List<Number>) {
l.contains1(<!TYPE_MISMATCH!>""<!>)
}
@Suppress("INVISIBLE_MEMBER", "INVISIBLE_REFERENCE")
fun <T> assertEquals1(e1: T, e2: @NoInfer T): Boolean = true
fun test(s: String) {
assertEquals1(s, <!CONSTANT_EXPECTED_TYPE_MISMATCH!>11<!>)
}
@@ -0,0 +1,10 @@
package
@kotlin.Suppress(names = {"INVISIBLE_MEMBER", "INVISIBLE_REFERENCE"}) public fun </*0*/ T> assertEquals1(/*0*/ e1: T, /*1*/ e2: @kotlin.NoInfer() T): kotlin.Boolean
public fun test(/*0*/ l: kotlin.List<kotlin.Number>): kotlin.Unit
public fun test(/*0*/ s: kotlin.String): kotlin.Unit
@kotlin.Suppress(names = {"INVISIBLE_MEMBER", "INVISIBLE_REFERENCE"}) public fun </*0*/ T> test1(/*0*/ t1: T, /*1*/ t2: @kotlin.NoInfer() T): T
@kotlin.Suppress(names = {"INVISIBLE_MEMBER", "INVISIBLE_REFERENCE"}) public fun </*0*/ T> test3(/*0*/ t1: @kotlin.NoInfer() T): T
public fun usage(): kotlin.Unit
@kotlin.Suppress(names = {"INVISIBLE_MEMBER", "INVISIBLE_REFERENCE"}) public fun </*0*/ T> kotlin.List<T>.contains1(/*0*/ e: @kotlin.NoInfer() T): kotlin.Boolean
@kotlin.Suppress(names = {"INVISIBLE_MEMBER", "INVISIBLE_REFERENCE"}) public fun </*0*/ T> @kotlin.NoInfer() T.test2(/*0*/ t1: T): T
@@ -7293,6 +7293,27 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("compiler/testData/diagnostics/tests/inference/annotationsForResolve")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class AnnotationsForResolve extends AbstractJetDiagnosticsTest {
public void testAllFilesPresentInAnnotationsForResolve() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/inference/annotationsForResolve"), Pattern.compile("^(.+)\\.kt$"), true);
}
@TestMetadata("exactAnnotation.kt")
public void testExactAnnotation() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/annotationsForResolve/exactAnnotation.kt");
doTest(fileName);
}
@TestMetadata("noInferAnnotation.kt")
public void testNoInferAnnotation() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inference/annotationsForResolve/noInferAnnotation.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/diagnostics/tests/inference/capturedTypes")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
+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"
}