Report warning on 'class object'
This commit is contained in:
@@ -191,6 +191,8 @@ public interface Errors {
|
|||||||
DiagnosticFactory0<JetObjectDeclaration> MANY_DEFAULT_OBJECTS = DiagnosticFactory0.create(ERROR, DEFAULT_OBJECT);
|
DiagnosticFactory0<JetObjectDeclaration> MANY_DEFAULT_OBJECTS = DiagnosticFactory0.create(ERROR, DEFAULT_OBJECT);
|
||||||
DiagnosticFactory0<JetObjectDeclaration> DEFAULT_OBJECT_NOT_ALLOWED = DiagnosticFactory0.create(ERROR, DEFAULT_OBJECT);
|
DiagnosticFactory0<JetObjectDeclaration> DEFAULT_OBJECT_NOT_ALLOWED = DiagnosticFactory0.create(ERROR, DEFAULT_OBJECT);
|
||||||
|
|
||||||
|
DiagnosticFactory0<JetObjectDeclaration> DEPRECATED_CLASS_OBJECT_SYNTAX = DiagnosticFactory0.create(WARNING);
|
||||||
|
|
||||||
// Objects
|
// Objects
|
||||||
|
|
||||||
DiagnosticFactory1<JetObjectDeclaration, ClassDescriptor> LOCAL_OBJECT_NOT_ALLOWED = DiagnosticFactory1.create(ERROR, DECLARATION_NAME);
|
DiagnosticFactory1<JetObjectDeclaration, ClassDescriptor> LOCAL_OBJECT_NOT_ALLOWED = DiagnosticFactory1.create(ERROR, DECLARATION_NAME);
|
||||||
|
|||||||
+3
@@ -272,6 +272,9 @@ public class DefaultErrorMessages {
|
|||||||
|
|
||||||
MAP.put(MANY_DEFAULT_OBJECTS, "Only one default object is allowed per class");
|
MAP.put(MANY_DEFAULT_OBJECTS, "Only one default object is allowed per class");
|
||||||
MAP.put(DEFAULT_OBJECT_NOT_ALLOWED, "A default object is not allowed here");
|
MAP.put(DEFAULT_OBJECT_NOT_ALLOWED, "A default object is not allowed here");
|
||||||
|
|
||||||
|
MAP.put(DEPRECATED_CLASS_OBJECT_SYNTAX, "'class object' syntax for default objects was deprecated. Use 'default' modifier instead");
|
||||||
|
|
||||||
MAP.put(LOCAL_OBJECT_NOT_ALLOWED, "Named object ''{0}'' is a singleton and cannot be local. Try to use anonymous object instead", NAME);
|
MAP.put(LOCAL_OBJECT_NOT_ALLOWED, "Named object ''{0}'' is a singleton and cannot be local. Try to use anonymous object instead", NAME);
|
||||||
MAP.put(LOCAL_ENUM_NOT_ALLOWED, "Enum class ''{0}'' cannot be local", NAME);
|
MAP.put(LOCAL_ENUM_NOT_ALLOWED, "Enum class ''{0}'' cannot be local", NAME);
|
||||||
MAP.put(DELEGATION_IN_TRAIT, "Traits cannot use delegation");
|
MAP.put(DELEGATION_IN_TRAIT, "Traits cannot use delegation");
|
||||||
|
|||||||
@@ -256,12 +256,19 @@ public class DeclarationsChecker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkObject(JetObjectDeclaration declaration, ClassDescriptor classDescriptor) {
|
private void checkObject(JetObjectDeclaration declaration, ClassDescriptor classDescriptor) {
|
||||||
|
checkDeprecatedClassObjectSyntax(declaration);
|
||||||
reportErrorIfHasIllegalModifier(declaration);
|
reportErrorIfHasIllegalModifier(declaration);
|
||||||
if (declaration.isLocal() && !declaration.isDefault() && !declaration.isObjectLiteral()) {
|
if (declaration.isLocal() && !declaration.isDefault() && !declaration.isObjectLiteral()) {
|
||||||
trace.report(LOCAL_OBJECT_NOT_ALLOWED.on(declaration, classDescriptor));
|
trace.report(LOCAL_OBJECT_NOT_ALLOWED.on(declaration, classDescriptor));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkDeprecatedClassObjectSyntax(@NotNull JetObjectDeclaration declaration) {
|
||||||
|
if (declaration.getClassKeyword() != null) {
|
||||||
|
trace.report(DEPRECATED_CLASS_OBJECT_SYNTAX.on(declaration));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void checkClass(BodiesResolveContext c, JetClass aClass, ClassDescriptorWithResolutionScopes classDescriptor) {
|
private void checkClass(BodiesResolveContext c, JetClass aClass, ClassDescriptorWithResolutionScopes classDescriptor) {
|
||||||
checkOpenMembers(classDescriptor);
|
checkOpenMembers(classDescriptor);
|
||||||
checkConstructorParameters(aClass);
|
checkConstructorParameters(aClass);
|
||||||
|
|||||||
@@ -1,17 +1,21 @@
|
|||||||
trait G
|
trait G
|
||||||
|
|
||||||
class A {
|
class A {
|
||||||
class object A {
|
<!DEPRECATED_CLASS_OBJECT_SYNTAX!>class object A<!> {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
trait B {
|
trait B {
|
||||||
class object : G {
|
<!DEPRECATED_CLASS_OBJECT_SYNTAX!>class object<!> : G {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class C {
|
||||||
|
default <!DEPRECATED_CLASS_OBJECT_SYNTAX!>class object<!>
|
||||||
|
}
|
||||||
|
|
||||||
fun main() {
|
fun main() {
|
||||||
A
|
A
|
||||||
A.A
|
A.A
|
||||||
|
|||||||
@@ -31,6 +31,20 @@ internal trait B {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal final class C {
|
||||||
|
public constructor C()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
|
||||||
|
internal default object Default {
|
||||||
|
private constructor Default()
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal trait G {
|
internal trait G {
|
||||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
|||||||
Reference in New Issue
Block a user