Prohibit callable references to annotation class constructors.
See KT-4391.
This commit is contained in:
@@ -503,6 +503,7 @@ public interface Errors {
|
||||
DiagnosticFactory0<KtExpression> CALLABLE_REFERENCE_LHS_NOT_A_CLASS = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtExpression> CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtExpression> CALLABLE_REFERENCE_TO_OBJECT_MEMBER = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtExpression> CALLABLE_REFERENCE_TO_ANNOTATION_CONSTRUCTOR = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
DiagnosticFactory0<KtExpression> CLASS_LITERAL_LHS_NOT_A_CLASS = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtExpression> ARRAY_CLASS_LITERAL_REQUIRES_ARGUMENT = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
+1
@@ -674,6 +674,7 @@ public class DefaultErrorMessages {
|
||||
"Left-hand side of a callable reference with a receiver parameter cannot be empty. " +
|
||||
"Please specify the type of the receiver before '::' explicitly");
|
||||
MAP.put(CALLABLE_REFERENCE_TO_OBJECT_MEMBER, "Callable references to object members are not supported");
|
||||
MAP.put(CALLABLE_REFERENCE_TO_ANNOTATION_CONSTRUCTOR, "Annotation class cannot be instantiated");
|
||||
|
||||
MAP.put(CLASS_LITERAL_LHS_NOT_A_CLASS, "Only classes are allowed on the left hand side of a class literal");
|
||||
MAP.put(ARRAY_CLASS_LITERAL_REQUIRES_ARGUMENT, "kotlin.Array class literal requires a type argument, please specify one in angle brackets");
|
||||
|
||||
+5
-1
@@ -719,9 +719,13 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
context.trace.report(CALLABLE_REFERENCE_TO_MEMBER_OR_EXTENSION_WITH_EMPTY_LHS.on(reference));
|
||||
}
|
||||
|
||||
if (DescriptorUtils.isObject(descriptor.getContainingDeclaration())) {
|
||||
DeclarationDescriptor containingDeclaration = descriptor.getContainingDeclaration();
|
||||
if (DescriptorUtils.isObject(containingDeclaration)) {
|
||||
context.trace.report(CALLABLE_REFERENCE_TO_OBJECT_MEMBER.on(reference));
|
||||
}
|
||||
if (descriptor instanceof ConstructorDescriptor && DescriptorUtils.isAnnotationClass(containingDeclaration)) {
|
||||
context.trace.report(CALLABLE_REFERENCE_TO_ANNOTATION_CONSTRUCTOR.on(reference));
|
||||
}
|
||||
|
||||
return CallableReferencesResolutionUtilsKt.createReflectionTypeForResolvedCallableReference(
|
||||
expression, lhsType, descriptor, context, components.reflectionTypes
|
||||
|
||||
Vendored
+1
-1
@@ -7,6 +7,6 @@ enum class D
|
||||
fun main() {
|
||||
::<!UNRESOLVED_REFERENCE!>A<!>
|
||||
::<!CREATING_AN_INSTANCE_OF_ABSTRACT_CLASS!>B<!>
|
||||
::C // KT-3465
|
||||
::<!CALLABLE_REFERENCE_TO_ANNOTATION_CONSTRUCTOR!>C<!> // KT-3465
|
||||
::<!INVISIBLE_MEMBER!>D<!>
|
||||
}
|
||||
Vendored
+5
@@ -0,0 +1,5 @@
|
||||
annotation class Ann(val prop: String)
|
||||
|
||||
val annCtorRef = ::<!CALLABLE_REFERENCE_TO_ANNOTATION_CONSTRUCTOR!>Ann<!>
|
||||
val annClassRef = Ann::class
|
||||
val annPropRef = Ann::prop
|
||||
Vendored
+13
@@ -0,0 +1,13 @@
|
||||
package
|
||||
|
||||
public val annClassRef: kotlin.reflect.KClass<Ann>
|
||||
public val annCtorRef: kotlin.reflect.KFunction1<kotlin.String, Ann>
|
||||
public val annPropRef: kotlin.reflect.KProperty1<Ann, kotlin.String>
|
||||
|
||||
public final annotation class Ann : kotlin.Annotation {
|
||||
public constructor Ann(/*0*/ prop: kotlin.String)
|
||||
public final val prop: kotlin.String
|
||||
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
|
||||
}
|
||||
@@ -1619,6 +1619,12 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("annotationClassConstructor.kt")
|
||||
public void testAnnotationClassConstructor() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/callableReference/function/annotationClassConstructor.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("callableRefrenceOnNestedObject.kt")
|
||||
public void testCallableRefrenceOnNestedObject() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/callableReference/function/callableRefrenceOnNestedObject.kt");
|
||||
|
||||
Reference in New Issue
Block a user