Refine diagnostics reported on implicit constructor delegation call

- Do not report anything else if primary's call expected

- Do not repeat EXPLICIT_DELEGATION_CALL_REQUIRED

 #KT-7230 Fixed
This commit is contained in:
Denis Zharkov
2015-05-07 11:22:34 +03:00
parent 87be626848
commit 6df805d6f2
7 changed files with 62 additions and 1 deletions
@@ -352,6 +352,7 @@ public class CallResolver {
context.trace.report(PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED.on(
(JetConstructorDelegationCall) calleeExpression.getParent()
));
if (call.isImplicit()) return OverloadResolutionResultsImpl.nameNotFound();
}
if (constructors.isEmpty()) {
@@ -82,7 +82,11 @@ public class TracingStrategyForImplicitConstructorDelegationCall(
}
private fun reportError(trace: BindingTrace) {
trace.report(Errors.EXPLICIT_DELEGATION_CALL_REQUIRED.on(delegationCall))
if (!trace.getBindingContext().getDiagnostics().forElement(delegationCall).
any { it.getFactory() == Errors.EXPLICIT_DELEGATION_CALL_REQUIRED }
) {
trace.report(Errors.EXPLICIT_DELEGATION_CALL_REQUIRED.on(delegationCall))
}
}
// Underlying methods should not be called because such errors are impossible
@@ -0,0 +1,7 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
open class A(p1: String)
class B() : A("") {
<!PRIMARY_CONSTRUCTOR_DELEGATION_CALL_EXPECTED!>constructor(s: String)<!> {
}
}
@@ -0,0 +1,16 @@
package
internal open class A {
public constructor A(/*0*/ p1: kotlin.String)
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 final class B : A {
public constructor B()
public constructor B(/*0*/ s: kotlin.String)
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
}
@@ -0,0 +1,6 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
open class A(p1: String, p2: String, p3: String, p4: String, p5: String)
class B : A {
<!EXPLICIT_DELEGATION_CALL_REQUIRED!>constructor(s: String)<!>
}
@@ -0,0 +1,15 @@
package
internal open class A {
public constructor A(/*0*/ p1: kotlin.String, /*1*/ p2: kotlin.String, /*2*/ p3: kotlin.String, /*3*/ p4: kotlin.String, /*4*/ p5: kotlin.String)
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 final class B : A {
public constructor B(/*0*/ s: kotlin.String)
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
}
@@ -10785,6 +10785,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("implicitSuperCallErrorsIfPrimary.kt")
public void testImplicitSuperCallErrorsIfPrimary() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/secondaryConstructors/implicitSuperCallErrorsIfPrimary.kt");
doTest(fileName);
}
@TestMetadata("initializationFromOtherInstance.kt")
public void testInitializationFromOtherInstance() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/secondaryConstructors/initializationFromOtherInstance.kt");
@@ -10863,6 +10869,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("reportResolutionErrorOnImplicitOnce.kt")
public void testReportResolutionErrorOnImplicitOnce() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/secondaryConstructors/reportResolutionErrorOnImplicitOnce.kt");
doTest(fileName);
}
@TestMetadata("resolvePropertyInitializerWithoutPrimary.kt")
public void testResolvePropertyInitializerWithoutPrimary() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/secondaryConstructors/resolvePropertyInitializerWithoutPrimary.kt");