diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnnotationResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnnotationResolver.java index 4f6272981c2..77f8398bd7c 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnnotationResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnnotationResolver.java @@ -94,12 +94,17 @@ public class AnnotationResolver { if (annotationEntryElements.isEmpty()) return Collections.emptyList(); List result = Lists.newArrayList(); for (JetAnnotationEntry entryElement : annotationEntryElements) { - AnnotationDescriptor descriptor = new AnnotationDescriptor(); - resolveAnnotationStub(scope, entryElement, descriptor, trace); - trace.record(BindingContext.ANNOTATION, entryElement, descriptor); + AnnotationDescriptor descriptor = trace.get(BindingContext.ANNOTATION, entryElement); + if (descriptor == null) { + descriptor = new AnnotationDescriptor(); + resolveAnnotationStub(scope, entryElement, descriptor, trace); + trace.record(BindingContext.ANNOTATION, entryElement, descriptor); + } + if (shouldResolveArguments) { resolveAnnotationArguments(entryElement, scope, trace); } + result.add(descriptor); } return result; @@ -360,15 +365,21 @@ public class AnnotationResolver { for (JetAnnotationEntry annotation : annotations) { AnnotationDescriptor annotationDescriptor = trace.get(BindingContext.ANNOTATION, annotation); if (annotationDescriptor == null) { - // TODO: Unresolved annotation - annotationDescriptor = new AnnotationDescriptor(); - annotationDescriptor.setAnnotationType(ErrorUtils.createErrorType("Unresolved annotation type")); - - trace.record(BindingContext.ANNOTATION, annotation, annotationDescriptor); + throw new IllegalStateException("Annotation for annotation should have been resolved: " + annotation); } result.add(annotationDescriptor); } + return result; } + + public static void reportUnsupportedAnnotationForTypeParameter(@NotNull JetModifierListOwner modifierListOwner, BindingTrace trace) { + JetModifierList modifierList = modifierListOwner.getModifierList(); + if (modifierList == null) return; + + for (JetAnnotationEntry annotationEntry : modifierList.getAnnotationEntries()) { + trace.report(Errors.UNSUPPORTED.on(annotationEntry, "Annotations for type parameters are not supported yet")); + } + } } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DeclarationResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DeclarationResolver.java index c8b3aa5fb60..50f3e3ac70f 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DeclarationResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DeclarationResolver.java @@ -227,7 +227,7 @@ public class DeclarationResolver { @Override public void visitObjectDeclaration(JetObjectDeclaration declaration) { PropertyDescriptor propertyDescriptor = descriptorResolver.resolveObjectDeclarationAsPropertyDescriptor( - namespaceLike.getOwnerForChildren(), declaration, context.getObjects().get(declaration), trace); + scopeForFunctions, namespaceLike.getOwnerForChildren(), declaration, context.getObjects().get(declaration), trace); namespaceLike.addPropertyDescriptor(propertyDescriptor); } @@ -239,7 +239,7 @@ public class DeclarationResolver { ((MutableClassDescriptorLite)namespaceLike.getOwnerForChildren()).getClassObjectDescriptor(); assert classObjectDescriptor != null; PropertyDescriptor propertyDescriptor = descriptorResolver.resolveObjectDeclarationAsPropertyDescriptor( - classObjectDescriptor, enumEntry, context.getClasses().get(enumEntry), trace); + scopeForFunctions, classObjectDescriptor, enumEntry, context.getClasses().get(enumEntry), trace); classObjectDescriptor.getBuilder().addPropertyDescriptor(propertyDescriptor); } }); diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java index fe8e7b11c70..c3a917a6ba1 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java @@ -102,9 +102,12 @@ public class DescriptorResolver { List typeParameters = Lists.newArrayList(); int index = 0; for (JetTypeParameter typeParameter : classElement.getTypeParameters()) { + // TODO: Support + AnnotationResolver.reportUnsupportedAnnotationForTypeParameter(typeParameter, trace); + TypeParameterDescriptor typeParameterDescriptor = TypeParameterDescriptorImpl.createForFurtherModification( descriptor, - annotationResolver.getResolvedAnnotations(typeParameter.getModifierList(), trace), + Collections.emptyList(), typeParameter.hasModifier(JetTokens.REIFIED_KEYWORD), typeParameter.getVariance(), JetPsiUtil.safeName(typeParameter.getName()), @@ -570,10 +573,12 @@ public class DescriptorResolver { trace.report(VARIANCE_ON_TYPE_PARAMETER_OF_FUNCTION_OR_PROPERTY.on(typeParameter)); } - // TODO: Annotations are not resolved! + // TODO: Support annotation for type parameters + AnnotationResolver.reportUnsupportedAnnotationForTypeParameter(typeParameter, trace); + TypeParameterDescriptorImpl typeParameterDescriptor = TypeParameterDescriptorImpl.createForFurtherModification( containingDescriptor, - annotationResolver.getResolvedAnnotations(typeParameter.getModifierList(), trace), + Collections.emptyList(), typeParameter.hasModifier(JetTokens.REIFIED_KEYWORD), typeParameter.getVariance(), JetPsiUtil.safeName(typeParameter.getName()), @@ -822,14 +827,14 @@ public class DescriptorResolver { @NotNull public VariableDescriptor resolveObjectDeclaration( + @NotNull JetScope scope, @NotNull DeclarationDescriptor containingDeclaration, @NotNull JetClassOrObject objectDeclaration, @NotNull ClassDescriptor classDescriptor, BindingTrace trace ) { - boolean isProperty = (containingDeclaration instanceof NamespaceDescriptor) - || (containingDeclaration instanceof ClassDescriptor); + boolean isProperty = (containingDeclaration instanceof NamespaceDescriptor) || (containingDeclaration instanceof ClassDescriptor); if (isProperty) { - return resolveObjectDeclarationAsPropertyDescriptor(containingDeclaration, objectDeclaration, classDescriptor, trace); + return resolveObjectDeclarationAsPropertyDescriptor(scope, containingDeclaration, objectDeclaration, classDescriptor, trace); } else { return resolveObjectDeclarationAsLocalVariable(containingDeclaration, objectDeclaration, classDescriptor, trace); @@ -838,6 +843,7 @@ public class DescriptorResolver { @NotNull public PropertyDescriptor resolveObjectDeclarationAsPropertyDescriptor( + @NotNull JetScope scope, @NotNull DeclarationDescriptor containingDeclaration, @NotNull JetClassOrObject objectDeclaration, @NotNull ClassDescriptor classDescriptor, BindingTrace trace @@ -845,7 +851,7 @@ public class DescriptorResolver { JetModifierList modifierList = objectDeclaration.getModifierList(); PropertyDescriptorImpl propertyDescriptor = new PropertyDescriptorForObjectImpl( containingDeclaration, - annotationResolver.getResolvedAnnotations(modifierList, trace), + annotationResolver.resolveAnnotationsWithoutArguments(scope, modifierList, trace), resolveVisibilityFromModifiers(objectDeclaration, getDefaultVisibilityForObjectPropertyDescriptor(classDescriptor)), JetPsiUtil.safeName(objectDeclaration.getName()), classDescriptor diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/descriptors/AbstractLazyMemberScope.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/descriptors/AbstractLazyMemberScope.java index 5d411a19fbf..a131f5632e0 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/descriptors/AbstractLazyMemberScope.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/lazy/descriptors/AbstractLazyMemberScope.java @@ -205,8 +205,11 @@ public abstract class AbstractLazyMemberScopeA1 A2(3) A2 A1(12) A2("Test") T> { + class InnerClass<A1 A2(3) A2 A1(12) A2("Test") T> { + fun test() { + class InFun<A1 A2(3) A2 A1(12) A2("Test") T> + } + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/AnnotationForFunctionTypeParameter.kt b/compiler/testData/diagnostics/tests/annotations/AnnotationForFunctionTypeParameter.kt new file mode 100644 index 00000000000..bd48f9c7251 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/AnnotationForFunctionTypeParameter.kt @@ -0,0 +1,12 @@ +annotation class A1 +annotation class A2(val some: Int = 12) + +fun <A1 A2(3) A2 A1(12) A2("Test") T> topFun() = 12 + +class SomeClass { + fun <A1 A2(3) A2 A1(12) A2("Test") T> method() = 12 + + fun foo() { + fun <A1 A2(3) A2 A1(12) A2("Test") T> innerFun() = 12 + } +} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/annotations/AnnotationsForPropertyTypeParameter.kt b/compiler/testData/diagnostics/tests/annotations/AnnotationsForPropertyTypeParameter.kt new file mode 100644 index 00000000000..f3fcf453855 --- /dev/null +++ b/compiler/testData/diagnostics/tests/annotations/AnnotationsForPropertyTypeParameter.kt @@ -0,0 +1,8 @@ +annotation class A1 +annotation class A2(val some: Int = 12) + +val <A1 A2(3) A2 A1(12) A2("Test") T> topProp = 12 + +class SomeClass { + val <A1 A2(3) A2 A1(12) A2("Test") T> field = 12 +} \ No newline at end of file diff --git a/compiler/testData/lazyResolve/namespaceComparator/UnresolvedAnnotationOnObject.kt b/compiler/testData/lazyResolve/namespaceComparator/UnresolvedAnnotationOnObject.kt new file mode 100644 index 00000000000..5652c10b9fe --- /dev/null +++ b/compiler/testData/lazyResolve/namespaceComparator/UnresolvedAnnotationOnObject.kt @@ -0,0 +1,9 @@ +package test + +// Checks that there is no rewrite error at ANNOTATION slice because of resolving annotations for object in lazy resolve and resolving +// object as property (method tries to resolve annotations too). + +BadAnnotation +object SomeObject + +val some = SomeObject diff --git a/compiler/testData/lazyResolve/namespaceComparator/UnresolvedAnnotationOnObject.txt b/compiler/testData/lazyResolve/namespaceComparator/UnresolvedAnnotationOnObject.txt new file mode 100644 index 00000000000..936827973e9 --- /dev/null +++ b/compiler/testData/lazyResolve/namespaceComparator/UnresolvedAnnotationOnObject.txt @@ -0,0 +1,8 @@ +package test + +[ERROR : Unresolved annotation type]() internal val SomeObject: test.SomeObject +internal val some: test.SomeObject + +[ERROR : Unresolved annotation type]() internal object SomeObject { + /*primary*/ private constructor SomeObject() +} diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 1f644b477c0..7e5170cfd2a 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -545,6 +545,16 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/annotations/AnnotatedConstructorParams.kt"); } + @TestMetadata("AnnotationForClassTypeParameter.kt") + public void testAnnotationForClassTypeParameter() throws Exception { + doTest("compiler/testData/diagnostics/tests/annotations/AnnotationForClassTypeParameter.kt"); + } + + @TestMetadata("AnnotationForFunctionTypeParameter.kt") + public void testAnnotationForFunctionTypeParameter() throws Exception { + doTest("compiler/testData/diagnostics/tests/annotations/AnnotationForFunctionTypeParameter.kt"); + } + @TestMetadata("AnnotationForObject.kt") public void testAnnotationForObject() throws Exception { doTest("compiler/testData/diagnostics/tests/annotations/AnnotationForObject.kt"); @@ -560,6 +570,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage doTest("compiler/testData/diagnostics/tests/annotations/AnnotationsForClasses.kt"); } + @TestMetadata("AnnotationsForPropertyTypeParameter.kt") + public void testAnnotationsForPropertyTypeParameter() throws Exception { + doTest("compiler/testData/diagnostics/tests/annotations/AnnotationsForPropertyTypeParameter.kt"); + } + @TestMetadata("BasicAnnotations.kt") public void testBasicAnnotations() throws Exception { doTest("compiler/testData/diagnostics/tests/annotations/BasicAnnotations.kt"); diff --git a/compiler/tests/org/jetbrains/jet/lang/resolve/lazy/LazyResolveNamespaceComparingTestGenerated.java b/compiler/tests/org/jetbrains/jet/lang/resolve/lazy/LazyResolveNamespaceComparingTestGenerated.java index 60037009bdd..b4cf239c965 100644 --- a/compiler/tests/org/jetbrains/jet/lang/resolve/lazy/LazyResolveNamespaceComparingTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/lang/resolve/lazy/LazyResolveNamespaceComparingTestGenerated.java @@ -2394,6 +2394,11 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso doTestCheckingPrimaryConstructors("compiler/testData/lazyResolve/namespaceComparator/simpleClass.kt"); } + @TestMetadata("UnresolvedAnnotationOnObject.kt") + public void testUnresolvedAnnotationOnObject() throws Exception { + doTestCheckingPrimaryConstructors("compiler/testData/lazyResolve/namespaceComparator/UnresolvedAnnotationOnObject.kt"); + } + @TestMetadata("varargIterator.kt") public void testVarargIterator() throws Exception { doTestCheckingPrimaryConstructors("compiler/testData/lazyResolve/namespaceComparator/varargIterator.kt");