From 66b4c8d1a929ae3f5776ccbe29724a6ea1b905d9 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Fri, 7 Mar 2014 20:34:26 +0400 Subject: [PATCH] CONFLICTING_UPPER_BOUNDS reported in LAZY mode --- .../jet/lang/resolve/DeclarationsChecker.java | 10 ++++-- .../jet/lang/resolve/DescriptorResolver.java | 35 +++++++++++-------- 2 files changed, 29 insertions(+), 16 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DeclarationsChecker.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DeclarationsChecker.java index c84c3d4b65f..b461367017f 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DeclarationsChecker.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DeclarationsChecker.java @@ -35,6 +35,7 @@ import java.util.*; import static org.jetbrains.jet.lang.diagnostics.Errors.*; import static org.jetbrains.jet.lang.resolve.BindingContext.TYPE; +import static org.jetbrains.jet.lang.resolve.BindingContext.TYPE_PARAMETER; public class DeclarationsChecker { @NotNull @@ -276,8 +277,13 @@ public class DeclarationsChecker { private void checkTypeParameters(JetTypeParameterListOwner typeParameterListOwner) { // TODO: Support annotation for type parameters - for (JetTypeParameter typeParameter : typeParameterListOwner.getTypeParameters()) { - AnnotationResolver.reportUnsupportedAnnotationForTypeParameter(typeParameter, trace); + for (JetTypeParameter jetTypeParameter : typeParameterListOwner.getTypeParameters()) { + AnnotationResolver.reportUnsupportedAnnotationForTypeParameter(jetTypeParameter, trace); + + TypeParameterDescriptor typeParameter = trace.get(TYPE_PARAMETER, jetTypeParameter); + if (typeParameter != null) { + DescriptorResolver.checkConflictingUpperBounds(trace, typeParameter, jetTypeParameter); + } } } 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 ddece8f5f1f..454f58c50a9 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/DescriptorResolver.java @@ -685,20 +685,7 @@ public class DescriptorResolver { parameter.setInitialized(); - if (KotlinBuiltIns.getInstance().isNothing(parameter.getUpperBoundsAsType())) { - PsiElement nameIdentifier = typeParameters.get(parameter.getIndex()).getNameIdentifier(); - if (nameIdentifier != null) { - trace.report(CONFLICTING_UPPER_BOUNDS.on(nameIdentifier, parameter)); - } - } - - JetType classObjectType = parameter.getClassObjectType(); - if (classObjectType != null && KotlinBuiltIns.getInstance().isNothing(classObjectType)) { - PsiElement nameIdentifier = typeParameters.get(parameter.getIndex()).getNameIdentifier(); - if (nameIdentifier != null) { - trace.report(CONFLICTING_CLASS_OBJECT_UPPER_BOUNDS.on(nameIdentifier, parameter)); - } - } + checkConflictingUpperBounds(trace, parameter, typeParameters.get(parameter.getIndex())); } if (!(declaration instanceof JetClass)) { @@ -710,6 +697,26 @@ public class DescriptorResolver { } } + public static void checkConflictingUpperBounds( + @NotNull BindingTrace trace, + @NotNull TypeParameterDescriptor parameter, + @NotNull JetTypeParameter typeParameter + ) { + PsiElement nameIdentifier = typeParameter.getNameIdentifier(); + if (KotlinBuiltIns.getInstance().isNothing(parameter.getUpperBoundsAsType())) { + if (nameIdentifier != null) { + trace.report(CONFLICTING_UPPER_BOUNDS.on(nameIdentifier, parameter)); + } + } + + JetType classObjectType = parameter.getClassObjectType(); + if (classObjectType != null && KotlinBuiltIns.getInstance().isNothing(classObjectType)) { + if (nameIdentifier != null) { + trace.report(CONFLICTING_CLASS_OBJECT_UPPER_BOUNDS.on(nameIdentifier, parameter)); + } + } + } + public void checkNamesInConstraints( @NotNull JetTypeParameterListOwner declaration, @NotNull DeclarationDescriptor descriptor,