From d0c72c2c3d8bf22eaf208664770213b3564724b8 Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Mon, 23 Mar 2015 19:42:51 +0300 Subject: [PATCH] Mark value arguments in case of empty delegation call It's useful for quickfixes for these diagnostics --- .../src/org/jetbrains/kotlin/diagnostics/Errors.java | 3 ++- .../jetbrains/kotlin/diagnostics/PositioningStrategies.kt | 3 ++- .../TracingStrategyForEmptyConstructorDelegationCall.kt | 3 +-- .../secondaryConstructors/errorsOnEmptyDelegationCall.kt | 8 ++++---- .../expectedPrimaryConstructorCall.kt | 2 +- .../secondaryConstructors/superSecondaryNonExisting.kt | 2 +- 6 files changed, 11 insertions(+), 10 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index 9fa9c967c04..350a7bb9725 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -168,7 +168,8 @@ public interface Errors { DiagnosticFactory0.create(ERROR); DiagnosticFactory0 PRIMARY_CONSTRUCTOR_REQUIRED_FOR_DATA_CLASS = DiagnosticFactory0.create(ERROR); - DiagnosticFactory0 EXPLICIT_DELEGATION_CALL_REQUIRED = DiagnosticFactory0.create(ERROR); + DiagnosticFactory0 EXPLICIT_DELEGATION_CALL_REQUIRED = + DiagnosticFactory0.create(ERROR, PositioningStrategies.SECONDARY_CONSTRUCTOR_DELEGATION_CALL); // Trait-specific diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt index 2b171a0727b..4122700374e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/PositioningStrategies.kt @@ -420,7 +420,8 @@ public object PositioningStrategies { override fun mark(element: JetConstructorDelegationCall): List { if (element.isEmpty()) { val constructor = element.getStrictParentOfType()!! - return markElement(constructor.getConstructorKeyword()) + val valueParameterList = constructor.getValueParameterList() ?: return markElement(constructor) + return markRange(constructor.getConstructorKeyword(), valueParameterList.getLastChild()) } return markElement(element.getCalleeExpression() ?: element) } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/TracingStrategyForEmptyConstructorDelegationCall.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/TracingStrategyForEmptyConstructorDelegationCall.kt index 7fdc07acc62..c3e6d612185 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/TracingStrategyForEmptyConstructorDelegationCall.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tasks/TracingStrategyForEmptyConstructorDelegationCall.kt @@ -82,8 +82,7 @@ public class TracingStrategyForEmptyConstructorDelegationCall( } private fun reportError(trace: BindingTrace) { - val declaration = delegationCall.getParent() as JetSecondaryConstructor - trace.report(Errors.EXPLICIT_DELEGATION_CALL_REQUIRED.on(declaration.getConstructorKeyword())) + trace.report(Errors.EXPLICIT_DELEGATION_CALL_REQUIRED.on(delegationCall)) } // Underlying methods should not be called because such errors are impossible diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/errorsOnEmptyDelegationCall.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/errorsOnEmptyDelegationCall.kt index a76c5a26ed6..cad517281d4 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/errorsOnEmptyDelegationCall.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/errorsOnEmptyDelegationCall.kt @@ -2,7 +2,7 @@ open class B0(x: Int) class A0 : B0 { - constructor() + constructor() constructor(x: Int) : super() } @@ -14,7 +14,7 @@ open class B1 { } class A1 : B1 { - constructor() + constructor() constructor(x: Int) : super() } @@ -26,7 +26,7 @@ open class B2 { } class A2 : B2 { - constructor() + constructor() constructor(x: Int) : super() } @@ -37,6 +37,6 @@ open class B3 { } class A3 : B3 { - constructor() + constructor() constructor(x: Int) : super() } diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/expectedPrimaryConstructorCall.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/expectedPrimaryConstructorCall.kt index d849121170c..653855d878c 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/expectedPrimaryConstructorCall.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/expectedPrimaryConstructorCall.kt @@ -1,6 +1,6 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER class A(x: Int) { - constructor() + constructor() } open class B(x: Int) class C(x: Int) : B(x) { diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/superSecondaryNonExisting.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/superSecondaryNonExisting.kt index fde881c5413..f8c63832afd 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/superSecondaryNonExisting.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/superSecondaryNonExisting.kt @@ -6,5 +6,5 @@ open class B(x: Double) { trait C class A : B, C { constructor(): super(' ') - constructor(x: Int) + constructor(x: Int) }