Report upper bounds violation for objects, not only classes

This commit is contained in:
Alexander Udalov
2013-10-18 20:11:09 +04:00
parent 01d8e658aa
commit 29f3c4a1a0
3 changed files with 33 additions and 24 deletions
@@ -395,37 +395,32 @@ public class TypeHierarchyResolver {
}
private void checkTypesInClassHeaders() {
for (Map.Entry<JetClass, MutableClassDescriptor> entry : context.getClasses().entrySet()) {
JetClass jetClass = entry.getKey();
for (JetClass jetClass : context.getClasses().keySet()) {
for (JetDelegationSpecifier delegationSpecifier : jetClass.getDelegationSpecifiers()) {
JetTypeReference typeReference = delegationSpecifier.getTypeReference();
if (typeReference != null) {
JetType type = trace.getBindingContext().get(TYPE, typeReference);
if (type != null) {
descriptorResolver.checkBounds(typeReference, type, trace);
}
}
checkBoundsForTypeInClassHeader(delegationSpecifier.getTypeReference());
}
for (JetTypeParameter jetTypeParameter : jetClass.getTypeParameters()) {
JetTypeReference extendsBound = jetTypeParameter.getExtendsBound();
if (extendsBound != null) {
JetType type = trace.getBindingContext().get(TYPE, extendsBound);
if (type != null) {
descriptorResolver.checkBounds(extendsBound, type, trace);
}
}
checkBoundsForTypeInClassHeader(jetTypeParameter.getExtendsBound());
}
for (JetTypeConstraint constraint : jetClass.getTypeConstraints()) {
JetTypeReference extendsBound = constraint.getBoundTypeReference();
if (extendsBound != null) {
JetType type = trace.getBindingContext().get(TYPE, extendsBound);
if (type != null) {
descriptorResolver.checkBounds(extendsBound, type, trace);
}
}
checkBoundsForTypeInClassHeader(constraint.getBoundTypeReference());
}
}
for (JetObjectDeclaration object : context.getObjects().keySet()) {
for (JetDelegationSpecifier delegationSpecifier : object.getDelegationSpecifiers()) {
checkBoundsForTypeInClassHeader(delegationSpecifier.getTypeReference());
}
}
}
private void checkBoundsForTypeInClassHeader(@Nullable JetTypeReference typeReference) {
if (typeReference != null) {
JetType type = trace.getBindingContext().get(TYPE, typeReference);
if (type != null) {
DescriptorResolver.checkBounds(typeReference, type, trace);
}
}
}
@@ -0,0 +1,9 @@
trait Trait<N : Number>
object O1 : Trait<Int>
object O2 : Trait<<!UPPER_BOUND_VIOLATED!>String<!>>
class C {
class object : Trait<<!UPPER_BOUND_VIOLATED!>IntRange<!>>
}
@@ -4303,6 +4303,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
doTest("compiler/testData/diagnostics/tests/objects/ObjectsNested.kt");
}
@TestMetadata("upperBoundViolated.kt")
public void testUpperBoundViolated() throws Exception {
doTest("compiler/testData/diagnostics/tests/objects/upperBoundViolated.kt");
}
}
@TestMetadata("compiler/testData/diagnostics/tests/operatorsOverloading")