KT-2744 Unneeded error message when the only super type is not resolved

#KT-2744 Fixed
This commit is contained in:
Natalia.Ukhorskaya
2012-09-11 15:17:13 +04:00
parent 8c87d31212
commit 199f10034b
5 changed files with 39 additions and 20 deletions
@@ -212,11 +212,10 @@ public abstract class MutableClassDescriptorLite extends ClassDescriptorBase
public void addSupertype(@NotNull JetType supertype) {
if (!ErrorUtils.isErrorType(supertype)) {
if (TypeUtils.getClassDescriptor(supertype) != null) {
// See the Errors.SUPERTYPE_NOT_A_CLASS_OR_TRAIT
supertypes.add(supertype);
}
assert !ErrorUtils.isErrorType(supertype) : "Error types must be filtered out in DescriptorResolver";
if (TypeUtils.getClassDescriptor(supertype) != null) {
// See the Errors.SUPERTYPE_NOT_A_CLASS_OR_TRAIT
supertypes.add(supertype);
}
}
@@ -130,25 +130,33 @@ public class DescriptorResolver {
) {
List<JetType> supertypes = Lists.newArrayList();
List<JetDelegationSpecifier> delegationSpecifiers = jetClass.getDelegationSpecifiers();
boolean isEnum = classDescriptor.getKind() == ClassKind.ENUM_CLASS;
if (delegationSpecifiers.isEmpty()) {
if (!isEnum) {
supertypes.add(getDefaultSupertype(jetClass, trace));
}
Collection<JetType> declaredSupertypes = resolveDelegationSpecifiers(
scope,
delegationSpecifiers,
typeResolver, trace, false);
for (JetType declaredSupertype : declaredSupertypes) {
addValidSupertype(supertypes, declaredSupertype);
}
else {
Collection<JetType> declaredSupertypes = resolveDelegationSpecifiers(
scope,
delegationSpecifiers,
typeResolver, trace, false);
supertypes.addAll(declaredSupertypes);
}
if (isEnum && !containsClass(supertypes)) {
if (classDescriptor.getKind() == ClassKind.ENUM_CLASS && !containsClass(supertypes)) {
supertypes.add(0, JetStandardLibrary.getInstance().getEnumType(classDescriptor.getDefaultType()));
}
if (supertypes.isEmpty()) {
JetType defaultSupertype = getDefaultSupertype(jetClass, trace);
addValidSupertype(supertypes, defaultSupertype);
}
return supertypes;
}
private static void addValidSupertype(List<JetType> supertypes, JetType declaredSupertype) {
if (!ErrorUtils.isErrorType(declaredSupertype)) {
supertypes.add(declaredSupertype);
}
}
private boolean containsClass(Collection<JetType> result) {
for (JetType type : result) {
ClassifierDescriptor descriptor = type.getConstructor().getDeclarationDescriptor();
@@ -54,7 +54,8 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements ClassDes
private static final Predicate<JetType> VALID_SUPERTYPE = new Predicate<JetType>() {
@Override
public boolean apply(JetType type) {
return !ErrorUtils.isErrorType(type) && (TypeUtils.getClassDescriptor(type) != null);
assert !ErrorUtils.isErrorType(type) : "Error types must be filtered out in DescriptorResolver";
return TypeUtils.getClassDescriptor(type) != null;
}
};
private final ResolveSession resolveSession;
@@ -0,0 +1,3 @@
class X : <!UNRESOLVED_REFERENCE!>S<!>
fun f(<!UNUSED_PARAMETER!>l<!>: List<X>) {}
@@ -15,13 +15,16 @@
*/
package org.jetbrains.jet.checkers;
import junit.framework.Assert;
import junit.framework.Test;
import junit.framework.TestSuite;
import java.io.File;
import org.jetbrains.jet.JetTestUtils;
import org.jetbrains.jet.test.InnerTestClasses;
import org.jetbrains.jet.test.TestMetadata;
import java.io.File;
import org.jetbrains.jet.checkers.AbstractDiagnosticsTestWithEagerResolve;
/** This class is generated by {@link org.jetbrains.jet.checkers.AbstractDiagnosticsTestWithEagerResolve}. DO NOT MODIFY MANUALLY */
@InnerTestClasses({JetDiagnosticsTestGenerated.Tests.class, JetDiagnosticsTestGenerated.Script.class})
@@ -3220,6 +3223,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
doTest("compiler/testData/diagnostics/tests/subtyping/kt2069.kt");
}
@TestMetadata("kt2744.kt")
public void testKt2744() throws Exception {
doTest("compiler/testData/diagnostics/tests/subtyping/kt2744.kt");
}
@TestMetadata("kt304.kt")
public void testKt304() throws Exception {
doTest("compiler/testData/diagnostics/tests/subtyping/kt304.kt");