From a00a118f9467f6e124ce86c687f2cb6ef56d18aa Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Sat, 21 Feb 2015 13:41:07 +0300 Subject: [PATCH] EA-63343 - assert: DescriptorUtils.getClassDescriptorForTypeConstructor #KT-6835 Fixed --- .../kotlin/resolve/AnnotationResolver.java | 6 +++++- .../annotations/typeParameterAsAnnotation.kt | 9 +++++++++ .../annotations/typeParameterAsAnnotation.txt | 17 +++++++++++++++++ .../checkers/JetDiagnosticsTestGenerated.java | 6 ++++++ 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 compiler/testData/diagnostics/tests/annotations/typeParameterAsAnnotation.kt create mode 100644 compiler/testData/diagnostics/tests/annotations/typeParameterAsAnnotation.txt diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationResolver.java b/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationResolver.java index dca0a27b4ae..5e8a7a2e79e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationResolver.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/AnnotationResolver.java @@ -154,7 +154,11 @@ public class AnnotationResolver { return ErrorUtils.createErrorType("No type reference: " + entryElement.getText()); } - return typeResolver.resolveType(scope, typeReference, new BindingTraceContext(), true); + JetType type = typeResolver.resolveType(scope, typeReference, new BindingTraceContext(), true); + if (!(type.getConstructor().getDeclarationDescriptor() instanceof ClassDescriptor)) { + return ErrorUtils.createErrorType("Not an annotation: " + type); + } + return type; } public static void checkAnnotationType( diff --git a/compiler/testData/diagnostics/tests/annotations/typeParameterAsAnnotation.kt b/compiler/testData/diagnostics/tests/annotations/typeParameterAsAnnotation.kt new file mode 100644 index 00000000000..355f4e5898a --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/typeParameterAsAnnotation.kt @@ -0,0 +1,9 @@ +class Foo { + [T] + fun foo() = 0 +} + +class Bar { + [T] + fun foo() = 0 +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/typeParameterAsAnnotation.txt b/compiler/testData/diagnostics/tests/annotations/typeParameterAsAnnotation.txt new file mode 100644 index 00000000000..044925bee67 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/typeParameterAsAnnotation.txt @@ -0,0 +1,17 @@ +package + +internal final class Bar { + public constructor Bar() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + [ERROR : Not an annotation: T]() internal final fun foo(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} + +internal final class Foo { + public constructor Foo() + public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean + [ERROR : Not an annotation: T]() internal final fun foo(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String +} diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java index 44beab74567..9a4fc2ab70c 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/JetDiagnosticsTestGenerated.java @@ -819,6 +819,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest(fileName); } + @TestMetadata("typeParameterAsAnnotation.kt") + public void testTypeParameterAsAnnotation() throws Exception { + String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/typeParameterAsAnnotation.kt"); + doTest(fileName); + } + @TestMetadata("UnresolvedAnnotationOnObject.kt") public void testUnresolvedAnnotationOnObject() throws Exception { String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/annotations/UnresolvedAnnotationOnObject.kt");