Object literals are now classes and expressions simultaneously for the purposes of annotation target checking
This commit is contained in:
@@ -173,6 +173,7 @@ public class AnnotationChecker(private val additionalCheckers: Iterable<Addition
|
||||
is JetClassInitializer -> TargetLists.T_INITIALIZER
|
||||
is JetMultiDeclaration -> TargetLists.T_MULTI_DECLARATION
|
||||
is JetFunctionLiteralExpression -> TargetLists.T_FUNCTION_LITERAL
|
||||
is JetObjectLiteralExpression -> TargetLists.T_OBJECT_LITERAL
|
||||
is JetExpression -> TargetLists.T_EXPRESSION
|
||||
else -> TargetLists.EMPTY
|
||||
}
|
||||
@@ -229,6 +230,8 @@ public class AnnotationChecker(private val additionalCheckers: Iterable<Addition
|
||||
|
||||
val T_FUNCTION_LITERAL = targetList(FUNCTION_LITERAL, FUNCTION, EXPRESSION)
|
||||
|
||||
val T_OBJECT_LITERAL = targetList(OBJECT_LITERAL, CLASS, EXPRESSION)
|
||||
|
||||
val T_TYPE_REFERENCE = targetList(TYPE) {
|
||||
onlyWithUseSiteTarget(VALUE_PARAMETER)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
@Target(AnnotationTarget.CLASS)
|
||||
annotation class Ann
|
||||
|
||||
open class My
|
||||
|
||||
fun foo(): My {
|
||||
return (@Ann object: My() {})
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
package
|
||||
|
||||
public fun foo(): My
|
||||
|
||||
@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.CLASS}) @kotlin.annotation.annotation() public final class Ann : kotlin.Annotation {
|
||||
public constructor Ann()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
|
||||
public open class My {
|
||||
public constructor My()
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -1064,6 +1064,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("objectLiteral.kt")
|
||||
public void testObjectLiteral() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/options/objectLiteral.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("repeatable.kt")
|
||||
public void testRepeatable() throws Exception {
|
||||
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/options/repeatable.kt");
|
||||
|
||||
@@ -24,7 +24,7 @@ import java.util.*
|
||||
// NOTE: this enum must have the same entries with kotlin.annotation.AnnotationTarget,
|
||||
// and may also have some additional entries
|
||||
public enum class KotlinTarget(val description: String, val isDefault: Boolean = true) {
|
||||
CLASS("class"), // includes CLASS_ONLY, OBJECT, INTERFACE, *_CLASS but not ENUM_ENTRY
|
||||
CLASS("class"), // includes CLASS_ONLY, OBJECT, OBJECT_LITERAL, INTERFACE, *_CLASS but not ENUM_ENTRY
|
||||
ANNOTATION_CLASS("annotation class"),
|
||||
TYPE_PARAMETER("type parameter", false),
|
||||
PROPERTY("property"), // includes *_PROPERTY, PROPERTY_PARAMETER, ENUM_ENTRY
|
||||
@@ -36,7 +36,7 @@ public enum class KotlinTarget(val description: String, val isDefault: Boolean =
|
||||
PROPERTY_GETTER("getter"),
|
||||
PROPERTY_SETTER("setter"),
|
||||
TYPE("type usage", false),
|
||||
EXPRESSION("expression", false), // includes FUNCTION_LITERAL
|
||||
EXPRESSION("expression", false), // includes FUNCTION_LITERAL, OBJECT_LITERAL
|
||||
FILE("file", false),
|
||||
|
||||
TYPE_PROJECTION("type projection", false),
|
||||
@@ -44,7 +44,7 @@ public enum class KotlinTarget(val description: String, val isDefault: Boolean =
|
||||
PROPERTY_PARAMETER("property constructor parameter", false),
|
||||
|
||||
CLASS_ONLY("class", false), // includes only top level classes and nested classes (but not enums, objects, interfaces, inner or local classes)
|
||||
OBJECT("object", false),
|
||||
OBJECT("object", false), // does not include OBJECT_LITERAL
|
||||
INTERFACE("interface", false),
|
||||
ENUM_CLASS("enum class", false),
|
||||
ENUM_ENTRY("enum entry", false),
|
||||
@@ -61,7 +61,8 @@ public enum class KotlinTarget(val description: String, val isDefault: Boolean =
|
||||
|
||||
INITIALIZER("initializer", false),
|
||||
MULTI_DECLARATION("multi declaration", false),
|
||||
FUNCTION_LITERAL("function literal", false)
|
||||
FUNCTION_LITERAL("function literal", false),
|
||||
OBJECT_LITERAL("object literal", false)
|
||||
;
|
||||
|
||||
companion object {
|
||||
|
||||
Reference in New Issue
Block a user