Prohibit DelegationBy specifier when no primary constructor

Also add codegen test for case when there is primary
This commit is contained in:
Denis Zharkov
2015-03-11 12:56:10 +03:00
parent 582755e71a
commit 70c573864a
6 changed files with 59 additions and 0 deletions
@@ -304,6 +304,9 @@ public class BodyResolver {
JetType expectedType = supertype != null ? supertype : NO_EXPECTED_TYPE;
typeInferrer.getType(scope, delegateExpression, expectedType, c.getOuterDataFlowInfo(), trace);
}
if (primaryConstructor == null) {
trace.report(UNSUPPORTED.on(specifier, "Delegation without primary constructor is not supported"));
}
}
@Override
@@ -0,0 +1,17 @@
trait A {
fun foo(): String
}
class B : A {
override fun foo() = "OK"
}
val global = B()
class C(x: Int) : A by global {
constructor(): this(1) {}
}
fun box(): String {
return C().foo()
}
@@ -0,0 +1,6 @@
trait A
class AImpl : A
class B : <!UNSUPPORTED!>A by AImpl()<!> {
constructor() {}
}
@@ -0,0 +1,21 @@
package
internal trait A {
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 AImpl : A {
public constructor AImpl()
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 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
}
@@ -10481,6 +10481,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("delegationByWithoutPrimary.kt")
public void testDelegationByWithoutPrimary() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/secondaryConstructors/delegationByWithoutPrimary.kt");
doTest(fileName);
}
@TestMetadata("enums.kt")
public void testEnums() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/secondaryConstructors/enums.kt");
@@ -6321,6 +6321,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest(fileName);
}
@TestMetadata("delegationWithPrimary.kt")
public void testDelegationWithPrimary() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/secondaryConstructors/delegationWithPrimary.kt");
doTest(fileName);
}
@TestMetadata("enums.kt")
public void testEnums() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/codegen/box/secondaryConstructors/enums.kt");