Refine diagnostics reported on primary constructors
This commit is contained in:
@@ -165,7 +165,7 @@ public interface Errors {
|
|||||||
|
|
||||||
DiagnosticFactory0<JetConstructorDelegationReferenceExpression> CYCLIC_CONSTRUCTOR_DELEGATION_CALL = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<JetConstructorDelegationReferenceExpression> CYCLIC_CONSTRUCTOR_DELEGATION_CALL = DiagnosticFactory0.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory0<JetSecondaryConstructor> SECONDARY_CONSTRUCTOR_IN_OBJECT = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<JetDeclaration> CONSTRUCTOR_IN_OBJECT = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
|
||||||
DiagnosticFactory0<JetDelegatorToSuperCall> SUPERTYPE_INITIALIZED_WITHOUT_PRIMARY_CONSTRUCTOR = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<JetDelegatorToSuperCall> SUPERTYPE_INITIALIZED_WITHOUT_PRIMARY_CONSTRUCTOR = DiagnosticFactory0.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory0<JetConstructorDelegationCall> PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED =
|
DiagnosticFactory0<JetConstructorDelegationCall> PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED =
|
||||||
@@ -188,7 +188,7 @@ public interface Errors {
|
|||||||
.create(WARNING, modifierSetPosition(JetTokens.OPEN_KEYWORD));
|
.create(WARNING, modifierSetPosition(JetTokens.OPEN_KEYWORD));
|
||||||
DiagnosticFactory0<JetModifierListOwner> TRAIT_CAN_NOT_BE_FINAL = DiagnosticFactory0.create(ERROR, FINAL_MODIFIER);
|
DiagnosticFactory0<JetModifierListOwner> TRAIT_CAN_NOT_BE_FINAL = DiagnosticFactory0.create(ERROR, FINAL_MODIFIER);
|
||||||
|
|
||||||
DiagnosticFactory0<PsiElement> CONSTRUCTOR_IN_TRAIT = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<JetDeclaration> CONSTRUCTOR_IN_TRAIT = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE);
|
||||||
|
|
||||||
DiagnosticFactory0<PsiElement> SUPERTYPE_INITIALIZED_IN_TRAIT = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<PsiElement> SUPERTYPE_INITIALIZED_IN_TRAIT = DiagnosticFactory0.create(ERROR);
|
||||||
|
|
||||||
|
|||||||
@@ -156,6 +156,11 @@ public object PositioningStrategies {
|
|||||||
is JetObjectDeclaration -> {
|
is JetObjectDeclaration -> {
|
||||||
return DECLARATION_NAME.mark(element)
|
return DECLARATION_NAME.mark(element)
|
||||||
}
|
}
|
||||||
|
is JetPrimaryConstructor -> {
|
||||||
|
val begin = element.getConstructorKeyword() ?: element.getValueParameterList() ?: return markElement(element)
|
||||||
|
val end = element.getValueParameterList() ?: element.getConstructorKeyword()
|
||||||
|
return markRange(begin, end)
|
||||||
|
}
|
||||||
is JetSecondaryConstructor -> {
|
is JetSecondaryConstructor -> {
|
||||||
return markRange(element.getConstructorKeyword(), element.getValueParameterList() ?: element.getConstructorKeyword())
|
return markRange(element.getConstructorKeyword(), element.getValueParameterList() ?: element.getConstructorKeyword())
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -403,7 +403,7 @@ public class DefaultErrorMessages {
|
|||||||
MAP.put(SINGLETON_IN_SUPERTYPE, "Cannot inherit from a singleton");
|
MAP.put(SINGLETON_IN_SUPERTYPE, "Cannot inherit from a singleton");
|
||||||
|
|
||||||
MAP.put(CYCLIC_CONSTRUCTOR_DELEGATION_CALL, "There's a cycle in the delegation calls chain");
|
MAP.put(CYCLIC_CONSTRUCTOR_DELEGATION_CALL, "There's a cycle in the delegation calls chain");
|
||||||
MAP.put(SECONDARY_CONSTRUCTOR_IN_OBJECT, "Constructors are not allowed for objects");
|
MAP.put(CONSTRUCTOR_IN_OBJECT, "Constructors are not allowed for objects");
|
||||||
MAP.put(SUPERTYPE_INITIALIZED_WITHOUT_PRIMARY_CONSTRUCTOR, "Supertype initialization is impossible without primary constructor");
|
MAP.put(SUPERTYPE_INITIALIZED_WITHOUT_PRIMARY_CONSTRUCTOR, "Supertype initialization is impossible without primary constructor");
|
||||||
MAP.put(PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED, "Primary constructor call expected");
|
MAP.put(PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED, "Primary constructor call expected");
|
||||||
MAP.put(DELEGATION_SUPER_CALL_IN_ENUM_CONSTRUCTOR, "Call to super is not allowed in enum constructor");
|
MAP.put(DELEGATION_SUPER_CALL_IN_ENUM_CONSTRUCTOR, "Call to super is not allowed in enum constructor");
|
||||||
|
|||||||
@@ -303,9 +303,9 @@ public class DeclarationsChecker {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void checkConstructorInTrait(JetClass klass) {
|
private void checkConstructorInTrait(JetClass klass) {
|
||||||
JetParameterList primaryConstructorParameterList = klass.getPrimaryConstructorParameterList();
|
JetPrimaryConstructor primaryConstructor = klass.getPrimaryConstructor();
|
||||||
if (primaryConstructorParameterList != null) {
|
if (primaryConstructor != null) {
|
||||||
trace.report(CONSTRUCTOR_IN_TRAIT.on(primaryConstructorParameterList));
|
trace.report(CONSTRUCTOR_IN_TRAIT.on(primaryConstructor));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import com.intellij.psi.util.PsiTreeUtil
|
|||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.diagnostics.Errors.CONSTRUCTOR_IN_TRAIT
|
import org.jetbrains.kotlin.diagnostics.Errors.CONSTRUCTOR_IN_TRAIT
|
||||||
import org.jetbrains.kotlin.diagnostics.Errors.MANY_COMPANION_OBJECTS
|
import org.jetbrains.kotlin.diagnostics.Errors.MANY_COMPANION_OBJECTS
|
||||||
import org.jetbrains.kotlin.diagnostics.Errors.SECONDARY_CONSTRUCTOR_IN_OBJECT
|
import org.jetbrains.kotlin.diagnostics.Errors.CONSTRUCTOR_IN_OBJECT
|
||||||
import org.jetbrains.kotlin.diagnostics.Errors.UNSUPPORTED
|
import org.jetbrains.kotlin.diagnostics.Errors.UNSUPPORTED
|
||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
@@ -176,7 +176,7 @@ public class LazyTopDownAnalyzer {
|
|||||||
}
|
}
|
||||||
else if (jetDeclaration is JetSecondaryConstructor) {
|
else if (jetDeclaration is JetSecondaryConstructor) {
|
||||||
if (DescriptorUtils.isSingletonOrAnonymousObject(classDescriptor)) {
|
if (DescriptorUtils.isSingletonOrAnonymousObject(classDescriptor)) {
|
||||||
trace!!.report(SECONDARY_CONSTRUCTOR_IN_OBJECT.on(jetDeclaration))
|
trace!!.report(CONSTRUCTOR_IN_OBJECT.on(jetDeclaration))
|
||||||
}
|
}
|
||||||
else if (classDescriptor.getKind() == ClassKind.INTERFACE) {
|
else if (classDescriptor.getKind() == ClassKind.INTERFACE) {
|
||||||
trace!!.report(CONSTRUCTOR_IN_TRAIT.on(jetDeclaration))
|
trace!!.report(CONSTRUCTOR_IN_TRAIT.on(jetDeclaration))
|
||||||
|
|||||||
@@ -4,10 +4,13 @@ interface T1<!CONSTRUCTOR_IN_TRAIT!>(val x: String)<!> {}
|
|||||||
|
|
||||||
interface T2<!CONSTRUCTOR_IN_TRAIT!>()<!> {}
|
interface T2<!CONSTRUCTOR_IN_TRAIT!>()<!> {}
|
||||||
|
|
||||||
interface T3<!CONSTRUCTOR_IN_TRAIT!>(<!UNUSED_PARAMETER!>a<!>: Int)<!> {}
|
interface T3 private <!CONSTRUCTOR_IN_TRAIT!>constructor(<!UNUSED_PARAMETER!>a<!>: Int)<!> {}
|
||||||
|
|
||||||
interface T4 {
|
interface T4 {
|
||||||
<!CONSTRUCTOR_IN_TRAIT!>constructor(a: <!DEBUG_INFO_MISSING_UNRESOLVED!>Int<!>) {
|
<!CONSTRUCTOR_IN_TRAIT!>constructor(a: <!DEBUG_INFO_MISSING_UNRESOLVED!>Int<!>)<!> {
|
||||||
val b: <!DEBUG_INFO_MISSING_UNRESOLVED!>Int<!> = 1
|
val b: <!DEBUG_INFO_MISSING_UNRESOLVED!>Int<!> = 1
|
||||||
}<!>
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface T5 private <!CONSTRUCTOR_IN_TRAIT!>()<!> : T4 {}
|
||||||
|
interface T6 <!CONSTRUCTOR_IN_TRAIT!>private<!><!SYNTAX!><!> : T5 {}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ internal interface T2 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal interface T3 {
|
internal interface T3 {
|
||||||
public constructor T3(/*0*/ a: kotlin.Int)
|
private constructor T3(/*0*/ a: kotlin.Int)
|
||||||
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
|
||||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
@@ -34,3 +34,15 @@ internal interface T4 {
|
|||||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal interface T5 : T4 {
|
||||||
|
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 interface T6 : T5 {
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|||||||
+8
-8
@@ -1,20 +1,20 @@
|
|||||||
object A {
|
object A {
|
||||||
<!SECONDARY_CONSTRUCTOR_IN_OBJECT!>constructor()
|
<!CONSTRUCTOR_IN_OBJECT!>constructor()<!>
|
||||||
<!>init {}
|
init {}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum class B {
|
enum class B {
|
||||||
X() {
|
X() {
|
||||||
<!SECONDARY_CONSTRUCTOR_IN_OBJECT!>constructor()
|
<!CONSTRUCTOR_IN_OBJECT!>constructor()<!>
|
||||||
<!>}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class C {
|
class C {
|
||||||
companion object {
|
companion object {
|
||||||
<!SECONDARY_CONSTRUCTOR_IN_OBJECT!>constructor()
|
<!CONSTRUCTOR_IN_OBJECT!>constructor()<!>
|
||||||
<!>}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val anonObject = object {
|
val anonObject = object {
|
||||||
<!SECONDARY_CONSTRUCTOR_IN_OBJECT!>constructor()
|
<!CONSTRUCTOR_IN_OBJECT!>constructor()<!>
|
||||||
<!>}
|
}
|
||||||
+2
-2
@@ -1,3 +1,3 @@
|
|||||||
interface A {
|
interface A {
|
||||||
<!CONSTRUCTOR_IN_TRAIT!>constructor()
|
<!CONSTRUCTOR_IN_TRAIT!>constructor()<!>
|
||||||
<!>}
|
}
|
||||||
+1
-1
@@ -6,4 +6,4 @@ class A {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class C <!PLATFORM_STATIC_ILLEGAL_USAGE!>platformStatic constructor()<!>
|
class C platformStatic <!PLATFORM_STATIC_ILLEGAL_USAGE!>constructor()<!>
|
||||||
|
|||||||
Reference in New Issue
Block a user