Report a separate diagnostic on inheritance from singletons
This commit is contained in:
@@ -139,6 +139,7 @@ public interface Errors {
|
||||
|
||||
|
||||
DiagnosticFactory0<JetTypeReference> FINAL_SUPERTYPE = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<JetTypeReference> SINGLETON_IN_SUPERTYPE = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<JetNullableType> NULLABLE_SUPERTYPE = DiagnosticFactory0.create(ERROR, NULLABLE_TYPE);
|
||||
|
||||
// Trait-specific
|
||||
|
||||
+2
-1
@@ -17,8 +17,8 @@
|
||||
package org.jetbrains.jet.lang.diagnostics.rendering;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.diagnostics.DiagnosticFactory;
|
||||
import org.jetbrains.jet.lang.diagnostics.Errors;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
||||
@@ -318,6 +318,7 @@ public class DefaultErrorMessages {
|
||||
MAP.put(CONSTRUCTOR_IN_TRAIT, "A trait may not have a constructor");
|
||||
MAP.put(SUPERTYPE_APPEARS_TWICE, "A supertype appears twice");
|
||||
MAP.put(FINAL_SUPERTYPE, "This type is final, so it cannot be inherited from");
|
||||
MAP.put(SINGLETON_IN_SUPERTYPE, "Cannot inherit from a singleton");
|
||||
|
||||
MAP.put(ILLEGAL_SELECTOR, "Expression ''{0}'' cannot be a selector (occur after a dot)", TO_STRING);
|
||||
|
||||
|
||||
@@ -256,10 +256,13 @@ public class BodyResolver {
|
||||
JetType supertype = trace.getBindingContext().get(BindingContext.TYPE, typeReference);
|
||||
recordSupertype(typeReference, supertype);
|
||||
if (supertype == null) return;
|
||||
ClassDescriptor classDescriptor = TypeUtils.getClassDescriptor(supertype);
|
||||
if (classDescriptor == null) return;
|
||||
if (descriptor.getKind() != ClassKind.TRAIT && !classDescriptor.getConstructors().isEmpty() &&
|
||||
!ErrorUtils.isError(classDescriptor) && classDescriptor.getKind() != ClassKind.TRAIT) {
|
||||
ClassDescriptor superClass = TypeUtils.getClassDescriptor(supertype);
|
||||
if (superClass == null) return;
|
||||
if (superClass.getKind().isSingleton()) {
|
||||
// A "singleton in supertype" diagnostic will be reported later
|
||||
return;
|
||||
}
|
||||
if (descriptor.getKind() != ClassKind.TRAIT && !superClass.getConstructors().isEmpty() && !ErrorUtils.isError(superClass)) {
|
||||
trace.report(SUPERTYPE_NOT_INITIALIZED.on(specifier));
|
||||
}
|
||||
}
|
||||
@@ -322,7 +325,10 @@ public class BodyResolver {
|
||||
trace.report(SUPERTYPE_APPEARS_TWICE.on(typeReference));
|
||||
}
|
||||
|
||||
if (constructor.isFinal() && !allowedFinalSupertypes.contains(constructor)) {
|
||||
if (DescriptorUtils.isSingleton(classDescriptor)) {
|
||||
trace.report(SINGLETON_IN_SUPERTYPE.on(typeReference));
|
||||
}
|
||||
else if (constructor.isFinal() && !allowedFinalSupertypes.contains(constructor)) {
|
||||
trace.report(FINAL_SUPERTYPE.on(typeReference));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user