allow delegated properties to have getters and setters without bodies

This commit is contained in:
Dmitry Jemerov
2015-03-04 13:50:58 +01:00
committed by Andrey Breslav
parent 8ba15937f9
commit e9266481c5
7 changed files with 60 additions and 3 deletions
@@ -203,7 +203,7 @@ public class DefaultErrorMessages {
MAP.put(ABSTRACT_PROPERTY_WITH_SETTER, "Property with setter implementation cannot be abstract");
MAP.put(ABSTRACT_DELEGATED_PROPERTY, "Delegated property cannot be abstract");
MAP.put(ACCESSOR_FOR_DELEGATED_PROPERTY, "Delegated property cannot have accessor");
MAP.put(ACCESSOR_FOR_DELEGATED_PROPERTY, "Delegated property cannot have accessors with non-default implementations");
MAP.put(DELEGATED_PROPERTY_IN_TRAIT, "Delegated properties are not allowed in traits");
MAP.put(LOCAL_VARIABLE_WITH_DELEGATE, "Local variables are not allowed to have delegates");
@@ -514,12 +514,12 @@ public class BodyResolver {
@NotNull JetScope propertyScope
) {
JetPropertyAccessor getter = jetProperty.getGetter();
if (getter != null) {
if (getter != null && getter.hasBody()) {
trace.report(ACCESSOR_FOR_DELEGATED_PROPERTY.on(getter));
}
JetPropertyAccessor setter = jetProperty.getSetter();
if (setter != null) {
if (setter != null && setter.hasBody()) {
trace.report(ACCESSOR_FOR_DELEGATED_PROPERTY.on(setter));
}
@@ -0,0 +1,10 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
val a: Int by Delegate()
get
class Delegate {
fun get(t: Any?, p: PropertyMetadata): Int {
return 1
}
}
@@ -0,0 +1,11 @@
package
internal val a: kotlin.Int
internal final class Delegate {
public constructor Delegate()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal final fun get(/*0*/ t: kotlin.Any?, /*1*/ p: kotlin.PropertyMetadata): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -0,0 +1,12 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
var a: Int by Delegate()
private set
class Delegate {
fun get(t: Any?, p: PropertyMetadata): Int {
return 1
}
fun set(t: Any?, p: PropertyMetadata, i: Int) {}
}
@@ -0,0 +1,12 @@
package
internal var a: kotlin.Int
internal final class Delegate {
public constructor Delegate()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal final fun get(/*0*/ t: kotlin.Any?, /*1*/ p: kotlin.PropertyMetadata): kotlin.Int
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
internal final fun set(/*0*/ t: kotlin.Any?, /*1*/ p: kotlin.PropertyMetadata, /*2*/ i: kotlin.Int): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -3129,6 +3129,18 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("defaultGetter.kt")
public void testDefaultGetter() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegatedProperty/defaultGetter.kt");
doTest(fileName);
}
@TestMetadata("defaultSetter.kt")
public void testDefaultSetter() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegatedProperty/defaultSetter.kt");
doTest(fileName);
}
@TestMetadata("delegatedPropertyOverridedInTrait.kt")
public void testDelegatedPropertyOverridedInTrait() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/delegatedProperty/delegatedPropertyOverridedInTrait.kt");