Disallow extension properties with backing fields

#KT-1682 Fixed
This commit is contained in:
Alexander Udalov
2014-05-28 19:17:31 +04:00
parent ea31f372aa
commit d78d4bc44c
72 changed files with 297 additions and 578 deletions
@@ -1790,6 +1790,7 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
boolean isStatic = containingDeclaration instanceof PackageFragmentDescriptor;
boolean isSuper = superExpression != null;
boolean isInsideClass = isCallInsideSameClassAsDeclared(propertyDescriptor, context);
boolean isExtensionProperty = propertyDescriptor.getReceiverParameter() != null;
JetType delegateType = getPropertyDelegateType(propertyDescriptor, bindingContext);
boolean isDelegatedProperty = delegateType != null;
@@ -1859,17 +1860,22 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
owner = callableMethod.getOwner();
}
String name;
if (propertyDescriptor.getContainingDeclaration() == backingFieldContext.getContextDescriptor()) {
assert backingFieldContext instanceof FieldOwnerContext : "Actual context is " + backingFieldContext + " but should be instance of FieldOwnerContext" ;
name = ((FieldOwnerContext) backingFieldContext).getFieldName(propertyDescriptor, isDelegatedProperty);
} else {
name = JvmAbi.getDefaultPropertyName(propertyDescriptor.getName(), isDelegatedProperty, propertyDescriptor.getReceiverParameter() != null);
String fieldName;
if (isExtensionProperty && !isDelegatedProperty) {
fieldName = null;
}
else if (propertyDescriptor.getContainingDeclaration() == backingFieldContext.getContextDescriptor()) {
assert backingFieldContext instanceof FieldOwnerContext
: "Actual context is " + backingFieldContext + " but should be instance of FieldOwnerContext";
fieldName = ((FieldOwnerContext) backingFieldContext).getFieldName(propertyDescriptor, isDelegatedProperty);
}
else {
fieldName = JvmAbi.getDefaultFieldNameForProperty(propertyDescriptor.getName(), isDelegatedProperty);
}
return StackValue.property(propertyDescriptor, owner,
typeMapper.mapType(isDelegatedProperty && forceField ? delegateType : propertyDescriptor.getOriginal().getType()),
isStatic, name, callableGetter, callableSetter, state);
isStatic, fieldName, callableGetter, callableSetter, state);
}
@@ -144,12 +144,12 @@ public abstract class StackValue {
@NotNull Type methodOwner,
@NotNull Type type,
boolean isStatic,
@NotNull String name,
@Nullable String fieldName,
@Nullable CallableMethod getter,
@Nullable CallableMethod setter,
GenerationState state
) {
return new Property(descriptor, methodOwner, getter, setter, isStatic, name, type, state);
return new Property(descriptor, methodOwner, getter, setter, isStatic, fieldName, type, state);
}
@NotNull
@@ -817,24 +817,19 @@ public abstract class StackValue {
}
static class Property extends StackValueWithSimpleReceiver {
@Nullable
private final CallableMethod getter;
@Nullable
private final CallableMethod setter;
@NotNull
public final Type methodOwner;
private final Type methodOwner;
@NotNull
private final PropertyDescriptor descriptor;
@NotNull
private final GenerationState state;
private final String name;
private final String fieldName;
public Property(
@NotNull PropertyDescriptor descriptor, @NotNull Type methodOwner,
@Nullable CallableMethod getter, @Nullable CallableMethod setter, boolean isStatic,
@NotNull String name, @NotNull Type type, @NotNull GenerationState state
@Nullable String fieldName, @NotNull Type type, @NotNull GenerationState state
) {
super(type, isStatic);
this.methodOwner = methodOwner;
@@ -842,14 +837,14 @@ public abstract class StackValue {
this.setter = setter;
this.descriptor = descriptor;
this.state = state;
this.name = name;
this.fieldName = fieldName;
}
@Override
public void put(Type type, InstructionAdapter v) {
if (getter == null) {
v.visitFieldInsn(isStatic ? GETSTATIC : GETFIELD, methodOwner.getInternalName(), getPropertyName(),
this.type.getDescriptor());
assert fieldName != null : "Property should have either a getter or a field name: " + descriptor;
v.visitFieldInsn(isStatic ? GETSTATIC : GETFIELD, methodOwner.getInternalName(), fieldName, this.type.getDescriptor());
genNotNullAssertionForField(v, state, descriptor);
coerceTo(type, v);
}
@@ -864,18 +859,15 @@ public abstract class StackValue {
public void store(Type topOfStackType, InstructionAdapter v) {
coerceFrom(topOfStackType, v);
if (setter == null) {
v.visitFieldInsn(isStatic ? PUTSTATIC : PUTFIELD, methodOwner.getInternalName(), getPropertyName(),
this.type.getDescriptor()); }
assert fieldName != null : "Property should have either a setter or a field name: " + descriptor;
v.visitFieldInsn(isStatic ? PUTSTATIC : PUTFIELD, methodOwner.getInternalName(), fieldName, this.type.getDescriptor());
}
else {
Method method = setter.getAsmMethod();
v.visitMethodInsn(setter.getInvokeOpcode(), setter.getOwner().getInternalName(), method.getName(), method.getDescriptor());
}
}
private String getPropertyName() {
return name;
}
public boolean isPropertyWithBackingFieldInOuterClass() {
return descriptor instanceof AccessorForPropertyBackingFieldInOuterClass;
}
@@ -44,16 +44,11 @@ public abstract class FieldOwnerContext<T extends DeclarationDescriptor> extends
}
@NotNull
public String getFieldName(@NotNull PropertyDescriptor descriptor, boolean isDelegated) {
public String getFieldName(@NotNull PropertyDescriptor possiblySubstitutedDescriptor, boolean isDelegated) {
PropertyDescriptor descriptor = possiblySubstitutedDescriptor.getOriginal();
assert descriptor.getKind().isReal() : "Only declared properties can have backing fields: " + descriptor;
boolean isExtension = descriptor.getReceiverParameter() != null;
return getFieldName(descriptor.getOriginal(), isDelegated, isExtension);
}
@NotNull
private String getFieldName(@NotNull PropertyDescriptor descriptor, boolean isDelegated, boolean isExtension) {
String defaultPropertyName = JvmAbi.getDefaultPropertyName(descriptor.getName(), isDelegated, isExtension);
String defaultPropertyName = JvmAbi.getDefaultFieldNameForProperty(descriptor.getName(), isDelegated);
Map<PropertyDescriptor, String> descriptor2Name = fieldNames.get(defaultPropertyName);
if (descriptor2Name == null) {
@@ -263,6 +263,7 @@ public interface Errors {
DiagnosticFactory0<JetProperty> MUST_BE_INITIALIZED = DiagnosticFactory0.create(ERROR, NAMED_ELEMENT);
DiagnosticFactory0<JetProperty> MUST_BE_INITIALIZED_OR_BE_ABSTRACT = DiagnosticFactory0.create(ERROR, NAMED_ELEMENT);
DiagnosticFactory0<JetExpression> EXTENSION_PROPERTY_WITH_BACKING_FIELD = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<JetExpression> PROPERTY_INITIALIZER_NO_BACKING_FIELD = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<JetExpression> PROPERTY_INITIALIZER_IN_TRAIT = DiagnosticFactory0.create(ERROR);
DiagnosticFactory0<JetProperty> FINAL_PROPERTY_IN_TRAIT = DiagnosticFactory0.create(ERROR, FINAL_MODIFIER);
@@ -131,6 +131,7 @@ public class DefaultErrorMessages {
MAP.put(MUST_BE_INITIALIZED_OR_BE_ABSTRACT, "Property must be initialized or be abstract");
MAP.put(PROPERTY_INITIALIZER_IN_TRAIT, "Property initializers are not allowed in traits");
MAP.put(FINAL_PROPERTY_IN_TRAIT, "Abstract property in trait cannot be final");
MAP.put(EXTENSION_PROPERTY_WITH_BACKING_FIELD, "Extension property cannot be initialized because it has no backing field");
MAP.put(PROPERTY_INITIALIZER_NO_BACKING_FIELD, "Initializer is not allowed here because this property has no backing field");
MAP.put(ABSTRACT_PROPERTY_IN_NON_ABSTRACT_CLASS, "Abstract property ''{0}'' in non-abstract class ''{1}''", STRING, NAME);
MAP.put(ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS, "Abstract function ''{0}'' in non-abstract class ''{1}''", STRING, NAME);
@@ -402,10 +402,7 @@ public class DeclarationsChecker {
}
}
private void checkPropertyInitializer(
@NotNull JetProperty property,
@NotNull PropertyDescriptor propertyDescriptor
) {
private void checkPropertyInitializer(@NotNull JetProperty property, @NotNull PropertyDescriptor propertyDescriptor) {
JetPropertyAccessor getter = property.getGetter();
JetPropertyAccessor setter = property.getSetter();
boolean hasAccessorImplementation = (getter != null && getter.hasBody()) ||
@@ -421,14 +418,17 @@ public class DeclarationsChecker {
boolean inTrait = containingDeclaration instanceof ClassDescriptor && ((ClassDescriptor)containingDeclaration).getKind() == ClassKind.TRAIT;
JetExpression initializer = property.getInitializer();
JetPropertyDelegate delegate = property.getDelegate();
boolean backingFieldRequired = trace.getBindingContext().get(BindingContext.BACKING_FIELD_REQUIRED, propertyDescriptor);
boolean backingFieldRequired =
Boolean.TRUE.equals(trace.getBindingContext().get(BindingContext.BACKING_FIELD_REQUIRED, propertyDescriptor));
if (inTrait && backingFieldRequired && hasAccessorImplementation) {
trace.report(BACKING_FIELD_IN_TRAIT.on(property));
}
if (initializer == null && delegate == null) {
boolean error = false;
if (backingFieldRequired && !inTrait && !trace.getBindingContext().get(BindingContext.IS_INITIALIZED, propertyDescriptor)) {
if (backingFieldRequired && !inTrait &&
Boolean.FALSE.equals(trace.getBindingContext().get(BindingContext.IS_INITIALIZED, propertyDescriptor))) {
if (!(containingDeclaration instanceof ClassDescriptor) || hasAccessorImplementation) {
error = true;
trace.report(MUST_BE_INITIALIZED.on(property));
@@ -446,6 +446,7 @@ public class DeclarationsChecker {
}
return;
}
if (inTrait) {
if (delegate != null) {
trace.report(DELEGATED_PROPERTY_IN_TRAIT.on(delegate));
@@ -454,8 +455,13 @@ public class DeclarationsChecker {
trace.report(PROPERTY_INITIALIZER_IN_TRAIT.on(initializer));
}
}
else if (!backingFieldRequired && delegate == null) {
trace.report(PROPERTY_INITIALIZER_NO_BACKING_FIELD.on(initializer));
else if (delegate == null) {
if (!backingFieldRequired) {
trace.report(PROPERTY_INITIALIZER_NO_BACKING_FIELD.on(initializer));
}
else if (property.getReceiverTypeRef() != null) {
trace.report(EXTENSION_PROPERTY_WITH_BACKING_FIELD.on(initializer));
}
}
}
@@ -0,0 +1,21 @@
class A {
var result = "Fail"
private var Int.foo: String
get() = result
private set(value) {
result = value
}
fun run(): String {
class O {
fun run() {
42.foo = "OK"
}
}
O().run()
return (-42).foo
}
}
fun box() = A().run()
@@ -1,11 +1,12 @@
class Test {
val Int.foo: String = "OK"
val Int.foo: String
get() = "OK"
fun test(): String {
return 1.foo
}
fun test(): String {
return 1.foo
}
}
fun box(): String {
return Test().test()
}
return Test().test()
}
@@ -1,16 +1,28 @@
class Test {
var Double.fooDouble: String = "fail"
var Long.fooLong: String = "fail"
var doubleStorage = "fail"
var longStorage = "fail"
fun test(): String {
val d = 1.0
d.fooDouble = "O"
val l = 1.toLong()
l.fooLong = "K"
return d.fooDouble + l.fooLong
}
var Double.foo: String
get() = doubleStorage
set(value) {
doubleStorage = value
}
var Long.bar: String
get() = longStorage
set(value) {
longStorage = value
}
fun test(): String {
val d = 1.0
d.foo = "O"
val l = 1L
l.bar = "K"
return d.foo + l.bar
}
}
fun box(): String {
return Test().test()
}
return Test().test()
}
@@ -1,13 +0,0 @@
class Test {
var Int.foo: String = "fail"
fun test(): String {
val i = 1
i.foo = "OK"
return i.foo
}
}
fun box(): String {
return Test().test()
}
@@ -1,15 +1,14 @@
class Test {
val Int.foo: String = "OK"
get() {
val a = $foo
return "OK"
}
val Int.foo: String
get() {
return "OK"
}
fun test(): String {
return 1.foo
}
fun test(): String {
return 1.foo
}
}
fun box(): String {
return Test().test()
}
return Test().test()
}
@@ -1,15 +1,14 @@
class Test {
private val Int.foo: String = "OK"
get() {
val a = $foo
return "OK"
}
private val Int.foo: String
get() {
return "OK"
}
fun test(): String {
return 1.foo
}
fun test(): String {
return 1.foo
}
}
fun box(): String {
return Test().test()
}
return Test().test()
}
@@ -1,16 +1,19 @@
class Test {
var Int.foo: String = "OK"
private set(str: String) {
$foo = str
}
var storage = "Fail"
fun test(): String {
val i = 1
i.foo = "OK"
return i.foo
}
var Int.foo: String
get() = storage
private set(str: String) {
storage = str
}
fun test(): String {
val i = 1
i.foo = "OK"
return i.foo
}
}
fun box(): String {
return Test().test()
}
return Test().test()
}
@@ -1,16 +1,19 @@
class Test {
var Int.foo: String = "fail"
set(str: String) {
$foo = str
}
var storage = "Fail"
fun test(): String {
val i = 1
i.foo = "OK"
return i.foo
}
var Int.foo: String
get() = storage
set(value) {
storage = value
}
fun test(): String {
val i = 1
i.foo = "OK"
return i.foo
}
}
fun box(): String {
return Test().test()
}
return Test().test()
}
@@ -1,5 +1,6 @@
val Int.foo: String = "OK"
val Int.foo: String
get() = "OK"
fun box(): String {
return 1.foo
}
return 1.foo
}
@@ -1,10 +1,22 @@
var Double.fooDouble: String = "fail"
var Long.fooLong: String = "fail"
var fooStorage = "Fail"
var barStorage = "Fail"
var Double.foo: String
get() = fooStorage
set(value) {
fooStorage = value
}
var Long.bar: String
get() = barStorage
set(value) {
barStorage = value
}
fun box(): String {
val d = 1.0
d.fooDouble = "O"
val l = 1.toLong()
l.fooLong = "K"
return d.fooDouble + l.fooLong
}
val d = 1.0
d.foo = "O"
val l = 1L
l.bar = "K"
return d.foo + l.bar
}
@@ -1,17 +0,0 @@
var Double.fooDouble: String = "fail"
set(str: String) {
$fooDouble = str
}
var Long.fooLong: String = "fail"
set(str: String) {
$fooLong = str
}
fun box(): String {
val d = 1.0
d.fooDouble = "O"
val l = 1.toLong()
l.fooLong = "K"
return d.fooDouble + l.fooLong
}
@@ -1,8 +0,0 @@
val Int.foo: String = "OK"
get() {
return $foo
}
fun box(): String {
return 1.foo
}
@@ -1,10 +0,0 @@
var Int.foo: String = "fail"
set(str: String) {
$foo = str
}
fun box(): String {
val i = 1
i.foo = "OK"
return i.foo
}
@@ -1,18 +0,0 @@
class A { }
class B { }
public val A.prop: Int = 0;
public val B.prop: String = "1111";
public val prop: Double = 0.1;
public fun doTest() : String {
if (A().prop != 0) return "fail1"
if (B().prop != "1111") return "fail2"
if (prop != 0.1) return "fail3"
return "OK"
}
fun box() : String {
return doTest()
}
@@ -1,22 +0,0 @@
class A { }
class B { }
class Test {
public val A.prop: Int = 0;
public val B.prop: String = "1111";
public val prop: Double = 0.1;
public fun doTest() : String {
if (A().prop != 0) return "fail1"
if (B().prop != "1111") return "fail2"
if (prop != 0.1) return "fail3"
return "OK"
}
}
fun box() : String {
return Test().doTest()
}
@@ -9,10 +9,10 @@ class B {
}
open class C
val C.attr = A()
val C.attr: A get() = A()
open class D: C()
val D.attr = B()
val D.attr: B get() = B()
fun box(): String {
@@ -3,27 +3,9 @@ val Int.getter: Int
return this@getter
}
var Int.setter1: Int = 2
get() {
return this@setter1
}
set(i: Int) {
$setter1 = this@setter1
}
var Int.setter2: Int = 2
set(i: Int) {
$setter2 = this@setter2
}
fun box(): String {
val i = 1
if (i.getter != 1) return "getter failed"
i.setter1 = 2
if (i.setter1 != 1) return "setter1 failed"
i.setter2 = 2
if (i.setter2 != 1) return "setter2 failed"
return "OK"
}
}
@@ -5,19 +5,9 @@ val Int.getter: Int
}.invoke()
}
var Int.setter: Int = 1
set(i: Int) {
$setter = {
this@setter
}.invoke()
}
fun box(): String {
val i = 1
if (i.getter != 1) return "getter failed"
i.setter = 2
if (i.setter != 1) return "setter failed"
return "OK"
}
}
@@ -7,7 +7,8 @@ val Int.getter: Int
}
var Int.setter: Int = 1
var Int.setter: Int
get() = 1
set(i: Int) {
val extFun = { Int.() ->
this@setter
@@ -24,4 +25,4 @@ fun box(): String {
if (i.setter != 1) return "setter failed"
return "OK"
}
}
@@ -4,50 +4,16 @@ trait Base {
val Int.getter: Int
get() {
return object: Base {
return object : Base {
override fun foo(): Int {
return this@getter
}
}.foo()
}
var Int.setter1: Int = 2
set(i: Int) {
$setter1 = object: Base {
override fun foo(): Int {
this@setter1
return 1
}
}.foo()
}
var Int.setter2: Int = 2
get() {
return object: Base {
override fun foo(): Int {
return this@setter2
}
}.foo()
}
set(i: Int) {
$setter2 = object: Base {
override fun foo(): Int {
this@setter2
return 1
}
}.foo()
}
fun box(): String {
val i = 1
if (i.getter != 1) return "getter failed"
i.setter1 = 2
if (i.setter1 != 1) return "setter1 failed"
i.setter2 = 2
if (i.setter2 != 1) return "setter2 failed"
return "OK"
}
}
@@ -2,7 +2,7 @@ package As
val staticProperty : String = "1"
val String.staticExt = "1"
val String.staticExt: String get() = "1"
open class A(val init: String) {
@@ -10,7 +10,7 @@ open class A(val init: String) {
private val privateProperty : String = init
val String.ext = "1"
val String.ext: String get() = "1"
val Int.myInc : Int
get() = this + 1
@@ -1,5 +1,5 @@
val Int.ext : () -> Int = { 5 }
val Long.ext : Long = 4.ext().toLong() //(c.kt:4)
val y : Long = 10.toLong().ext
val Int.ext: () -> Int get() = { 5 }
val Long.ext: Long get() = 4.ext().toLong() //(c.kt:4)
val y: Long get() = 10L.ext
fun box() : String = if (y == 5.toLong()) "OK" else "fail"
fun box(): String = if (y == 5L) "OK" else "fail: $y"
@@ -1,4 +1,4 @@
val Int.test = "test"
val Int.test: String get() = "test"
fun box(): String {
val x = "a ${1.test}"
@@ -2,7 +2,7 @@ enum class E {
entry
}
val Int.entry = 42
val Long.entry = 239
val Int.entry: Int get() = 42
val Long.entry: Int get() = 239
val e = E.entry
@@ -2,7 +2,7 @@
package outer
fun Int?.optint() : Unit {}
val Int?.optval : Unit = Unit.VALUE
val Int?.optval : Unit get() = Unit.VALUE
fun <T: Any, E> T.foo(<!UNUSED_PARAMETER!>x<!> : E, y : A) : T {
y.plus(1)
@@ -1,4 +1,3 @@
//KT-819 Redeclaration error for extension properties with the same name and different receivers
import java.io.*
@@ -15,16 +14,20 @@ open class A() {
open fun String.foo() {}
open fun Int.foo() {}
open val String.foo = 0
open val Int.foo = 1
open val String.foo: Int
get() = 0
open val Int.foo: Int
get() = 1
}
class B() : A() {
override fun String.foo() {}
override fun Int.foo() {}
override val String.foo = 0
override val Int.foo = 0
override val String.foo: Int
get() = 0
override val Int.foo: Int
get() = 0
fun use(s: String) {
s.foo
@@ -1,6 +1,6 @@
object O
fun Any.foo() = 42
val Any?.bar = 239
val Any?.bar: Int get() = 239
val x = O.foo() + O.bar
@@ -10,4 +10,5 @@ object A {
class B
val B.c : String = "test"
val B.c : String
get() = "test"
@@ -1,4 +1,4 @@
package foo
val Int.<!REDECLARATION!>foo<!> = 2
val Int.<!REDECLARATION!>foo<!> = 3
val Int.<!REDECLARATION!>foo<!>: Int get() = 2
val Int.<!REDECLARATION!>foo<!>: Int get() = 3
@@ -26,5 +26,5 @@ class C {
//KT-1728 Can't invoke extension property as a function
val Int.ext : () -> Int = { 5 }
val x = 1.ext()
val Int.ext : () -> Int get() = { 5 }
val x = 1.ext()
@@ -24,7 +24,8 @@ fun test(a: A) {
//variable as extension
trait B {
}
val B.foo = Foo()
val B.foo: Foo
get() = Foo()
fun test(b: B) {
b.foo()
@@ -22,7 +22,8 @@ fun test(a: A) {
//variable as extension
trait B {}
val B.foo = Foo()
val B.foo: Foo
get() = Foo()
fun test(b: B) {
@@ -40,7 +40,8 @@ fun test(c: C, b: B) {
//variable as extension,
trait D {
}
val D.foo = Foo()
val D.foo: Foo
get() = Foo()
class E {
fun Foo.invoke() {}
@@ -10,10 +10,12 @@ class B {
}
open class C
val C.attr = A()
val C.attr: A
get() = A()
open class D: C()
val D.attr = B()
val D.attr: B
get() = B()
fun main(args: Array<String>) {
@@ -1,10 +1,10 @@
package i
val <T> List<T>.length = <!UNRESOLVED_REFERENCE!>size<!>()
val <T> List<T>.length = <!EXTENSION_PROPERTY_WITH_BACKING_FIELD!><!UNRESOLVED_REFERENCE!>size<!>()<!>
val <T> List<T>.length1 : Int get() = size()
val String.bd = <!NO_THIS!>this<!> <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>+<!> "!"
val String.bd = <!EXTENSION_PROPERTY_WITH_BACKING_FIELD!><!NO_THIS!>this<!> <!DEBUG_INFO_ELEMENT_WITH_ERROR_TYPE!>+<!> "!"<!>
val String.bd1 : String get() = this + "!"
@@ -13,7 +13,7 @@ class A {
val ii : Int = 1
}
val A.foo = <!UNRESOLVED_REFERENCE!>ii<!>
val A.foo = <!UNRESOLVED_REFERENCE, EXTENSION_PROPERTY_WITH_BACKING_FIELD!>ii<!>
val A.foo1 : Int get() = ii
@@ -22,8 +22,8 @@ class C {
inner class D {}
}
val C.foo : C.D = <!UNRESOLVED_REFERENCE!>D<!>()
val C.foo : C.D = <!EXTENSION_PROPERTY_WITH_BACKING_FIELD!><!UNRESOLVED_REFERENCE!>D<!>()<!>
val C.bar : C.D = C().D()
val C.bar : C.D = <!EXTENSION_PROPERTY_WITH_BACKING_FIELD!>C().D()<!>
val C.foo1 : C.D get() = D()
val C.foo1 : C.D get() = D()
@@ -1,7 +1,7 @@
trait Base {
fun foo()
}
val String.test: Base = object: Base {
val String.test: Base = <!EXTENSION_PROPERTY_WITH_BACKING_FIELD!>object: Base<!> {
override fun foo() {
this<!UNRESOLVED_REFERENCE!>@test<!>
}
@@ -1,9 +1,9 @@
package test
val Long.date1: Object = java.util.Date()
val Long.date1: Any get() = java.util.Date()
internal val Long.date12: Object = java.util.Date()
internal val Long.date12: Any get() = java.util.Date()
private val Long.date3: java.util.Date = java.util.Date()
private val Long.date3: java.util.Date get() = java.util.Date()
public val Long.date4: java.util.Date = java.util.Date()
public val Long.date4: java.util.Date get() = java.util.Date()
@@ -1,9 +1,9 @@
package test
internal val kotlin.Long.date1: java.lang.Object
internal fun kotlin.Long.<get-date1>(): java.lang.Object
internal val kotlin.Long.date12: java.lang.Object
internal fun kotlin.Long.<get-date12>(): java.lang.Object
internal val kotlin.Long.date1: kotlin.Any
internal fun kotlin.Long.<get-date1>(): kotlin.Any
internal val kotlin.Long.date12: kotlin.Any
internal fun kotlin.Long.<get-date12>(): kotlin.Any
private val kotlin.Long.date3: java.util.Date
private fun kotlin.Long.<get-date3>(): java.util.Date
public val kotlin.Long.date4: java.util.Date
@@ -1,9 +1,28 @@
package test
var Long.date1: Object = java.util.Date()
var Long.date1: Any get() = java.util.Date()
set(value) {}
internal var Long.date12: Object = java.util.Date()
var Long.date2: Any get() = java.util.Date()
protected set(value) {}
private var Long.date3: java.util.Date = java.util.Date()
var Long.date3: Any get() = java.util.Date()
private set(value) {}
public var Long.date5: java.util.Date = java.util.Date()
private var Long.date4: java.util.Date get() = java.util.Date()
set(value) {}
public var Long.date7: java.util.Date get() = java.util.Date()
set(value) {}
public var Long.date8: java.util.Date get() = java.util.Date()
internal set(value) {}
public var Long.date9: java.util.Date get() = java.util.Date()
private set(value) {}
public var Long.date10: java.util.Date get() = java.util.Date()
protected set(value) {}
public var Long.date11: java.util.Date get() = java.util.Date()
public set(value) {}
@@ -1,14 +1,29 @@
package test
internal var kotlin.Long.date1: java.lang.Object
internal fun kotlin.Long.<get-date1>(): java.lang.Object
internal fun kotlin.Long.<set-date1>(/*0*/ <set-?>: java.lang.Object): kotlin.Unit
internal var kotlin.Long.date12: java.lang.Object
internal fun kotlin.Long.<get-date12>(): java.lang.Object
internal fun kotlin.Long.<set-date12>(/*0*/ <set-?>: java.lang.Object): kotlin.Unit
private var kotlin.Long.date3: java.util.Date
private fun kotlin.Long.<get-date3>(): java.util.Date
private fun kotlin.Long.<set-date3>(/*0*/ <set-?>: java.util.Date): kotlin.Unit
public var kotlin.Long.date5: java.util.Date
public fun kotlin.Long.<get-date5>(): java.util.Date
public fun kotlin.Long.<set-date5>(/*0*/ <set-?>: java.util.Date): kotlin.Unit
internal var kotlin.Long.date1: kotlin.Any
internal fun kotlin.Long.<get-date1>(): kotlin.Any
internal fun kotlin.Long.<set-date1>(/*0*/ value: kotlin.Any): kotlin.Unit
public var kotlin.Long.date10: java.util.Date
public fun kotlin.Long.<get-date10>(): java.util.Date
protected fun kotlin.Long.<set-date10>(/*0*/ value: java.util.Date): kotlin.Unit
public var kotlin.Long.date11: java.util.Date
public fun kotlin.Long.<get-date11>(): java.util.Date
public fun kotlin.Long.<set-date11>(/*0*/ value: java.util.Date): kotlin.Unit
internal var kotlin.Long.date2: kotlin.Any
internal fun kotlin.Long.<get-date2>(): kotlin.Any
protected fun kotlin.Long.<set-date2>(/*0*/ value: kotlin.Any): kotlin.Unit
internal var kotlin.Long.date3: kotlin.Any
internal fun kotlin.Long.<get-date3>(): kotlin.Any
private fun kotlin.Long.<set-date3>(/*0*/ value: kotlin.Any): kotlin.Unit
private var kotlin.Long.date4: java.util.Date
private fun kotlin.Long.<get-date4>(): java.util.Date
private fun kotlin.Long.<set-date4>(/*0*/ value: java.util.Date): kotlin.Unit
public var kotlin.Long.date7: java.util.Date
public fun kotlin.Long.<get-date7>(): java.util.Date
public fun kotlin.Long.<set-date7>(/*0*/ value: java.util.Date): kotlin.Unit
public var kotlin.Long.date8: java.util.Date
public fun kotlin.Long.<get-date8>(): java.util.Date
internal fun kotlin.Long.<set-date8>(/*0*/ value: java.util.Date): kotlin.Unit
public var kotlin.Long.date9: java.util.Date
public fun kotlin.Long.<get-date9>(): java.util.Date
private fun kotlin.Long.<set-date9>(/*0*/ value: java.util.Date): kotlin.Unit
@@ -1,28 +0,0 @@
package test
var Long.date1: Object = java.util.Date()
set
var Long.date2: Object = java.util.Date()
protected set
var Long.date3: Object = java.util.Date()
private set
private var Long.date4: java.util.Date = java.util.Date()
set
public var Long.date7: java.util.Date = java.util.Date()
set
public var Long.date8: java.util.Date = java.util.Date()
internal set
public var Long.date9: java.util.Date = java.util.Date()
private set
public var Long.date10: java.util.Date = java.util.Date()
protected set
public var Long.date11: java.util.Date = java.util.Date()
public set
@@ -1,29 +0,0 @@
package test
internal var kotlin.Long.date1: java.lang.Object
internal fun kotlin.Long.<get-date1>(): java.lang.Object
internal fun kotlin.Long.<set-date1>(/*0*/ <set-?>: java.lang.Object): kotlin.Unit
public var kotlin.Long.date10: java.util.Date
public fun kotlin.Long.<get-date10>(): java.util.Date
protected fun kotlin.Long.<set-date10>(/*0*/ <set-?>: java.util.Date): kotlin.Unit
public var kotlin.Long.date11: java.util.Date
public fun kotlin.Long.<get-date11>(): java.util.Date
public fun kotlin.Long.<set-date11>(/*0*/ <set-?>: java.util.Date): kotlin.Unit
internal var kotlin.Long.date2: java.lang.Object
internal fun kotlin.Long.<get-date2>(): java.lang.Object
protected fun kotlin.Long.<set-date2>(/*0*/ <set-?>: java.lang.Object): kotlin.Unit
internal var kotlin.Long.date3: java.lang.Object
internal fun kotlin.Long.<get-date3>(): java.lang.Object
private fun kotlin.Long.<set-date3>(/*0*/ <set-?>: java.lang.Object): kotlin.Unit
private var kotlin.Long.date4: java.util.Date
private fun kotlin.Long.<get-date4>(): java.util.Date
private fun kotlin.Long.<set-date4>(/*0*/ <set-?>: java.util.Date): kotlin.Unit
public var kotlin.Long.date7: java.util.Date
public fun kotlin.Long.<get-date7>(): java.util.Date
public fun kotlin.Long.<set-date7>(/*0*/ <set-?>: java.util.Date): kotlin.Unit
public var kotlin.Long.date8: java.util.Date
public fun kotlin.Long.<get-date8>(): java.util.Date
internal fun kotlin.Long.<set-date8>(/*0*/ <set-?>: java.util.Date): kotlin.Unit
public var kotlin.Long.date9: java.util.Date
public fun kotlin.Long.<get-date9>(): java.util.Date
private fun kotlin.Long.<set-date9>(/*0*/ <set-?>: java.util.Date): kotlin.Unit
@@ -1,13 +0,0 @@
class Test {
class object {
public val Test.prop: Int = 0;
}
}
// TESTED_OBJECT_KIND: property
// TESTED_OBJECTS: Test, prop$ext
// FLAGS: ACC_FINAL, ACC_STATIC, ACC_PRIVATE
// TESTED_OBJECT_KIND: property
// TESTED_OBJECTS: Test$object, prop$ext
// ABSENT: TRUE
@@ -1,13 +0,0 @@
class Test {
class object {
public var Test.prop: Int = 0;
}
}
// TESTED_OBJECT_KIND: property
// TESTED_OBJECTS: Test, prop$ext
// FLAGS: ACC_STATIC, ACC_PRIVATE
// TESTED_OBJECT_KIND: property
// TESTED_OBJECTS: Test$object, prop$ext
// ABSENT: TRUE
@@ -1,18 +0,0 @@
class A { }
class B { }
class Test {
class object {
public val A.prop: Int = 0;
public val B.prop: Int = 0;
}
}
// TESTED_OBJECT_KIND: property
// TESTED_OBJECTS: Test, prop$ext
// FLAGS: ACC_PRIVATE, ACC_FINAL, ACC_STATIC
// TESTED_OBJECT_KIND: property
// TESTED_OBJECTS: Test, prop$ext$1
// FLAGS: ACC_PRIVATE, ACC_FINAL, ACC_STATIC
@@ -1,16 +0,0 @@
class Test {
public val prop: Int = 0;
class object {
public var Test.prop: Int = 0;
}
}
// TESTED_OBJECT_KIND: property
// TESTED_OBJECTS: Test, prop
// FLAGS: ACC_PRIVATE, ACC_FINAL
// TESTED_OBJECT_KIND: property
// TESTED_OBJECTS: Test, prop$ext
// FLAGS: ACC_STATIC, ACC_PRIVATE
@@ -1,13 +0,0 @@
trait Test {
class object {
public val Test.prop: Int = 0;
}
}
// TESTED_OBJECT_KIND: property
// TESTED_OBJECTS: Test, prop$ext
// ABSENT: TRUE
// TESTED_OBJECT_KIND: property
// TESTED_OBJECTS: Test$object, prop$ext
// FLAGS: ACC_FINAL, ACC_PRIVATE
@@ -1,13 +0,0 @@
trait Test {
class object {
public var Test.prop: Int = 0;
}
}
// TESTED_OBJECT_KIND: property
// TESTED_OBJECTS: Test, prop$ext
// ABSENT: TRUE
// TESTED_OBJECT_KIND: property
// TESTED_OBJECTS: Test$object, prop$ext
// FLAGS: ACC_PRIVATE
@@ -500,16 +500,6 @@ public class WriteFlagsTestGenerated extends AbstractWriteFlagsTest {
doTest("compiler/testData/writeFlags/property/classObject/class/delegatedPublicVal.kt");
}
@TestMetadata("extensionPublicVal.kt")
public void testExtensionPublicVal() throws Exception {
doTest("compiler/testData/writeFlags/property/classObject/class/extensionPublicVal.kt");
}
@TestMetadata("extensionPublicVar.kt")
public void testExtensionPublicVar() throws Exception {
doTest("compiler/testData/writeFlags/property/classObject/class/extensionPublicVar.kt");
}
@TestMetadata("internalVal.kt")
public void testInternalVal() throws Exception {
doTest("compiler/testData/writeFlags/property/classObject/class/internalVal.kt");
@@ -608,16 +598,6 @@ public class WriteFlagsTestGenerated extends AbstractWriteFlagsTest {
doTest("compiler/testData/writeFlags/property/classObject/rename/delegatedAndProperty.kt");
}
@TestMetadata("extensionAndExtension.kt")
public void testExtensionAndExtension() throws Exception {
doTest("compiler/testData/writeFlags/property/classObject/rename/extensionAndExtension.kt");
}
@TestMetadata("extensionAndProperty.kt")
public void testExtensionAndProperty() throws Exception {
doTest("compiler/testData/writeFlags/property/classObject/rename/extensionAndProperty.kt");
}
@TestMetadata("propertyAndProperty.kt")
public void testPropertyAndProperty() throws Exception {
doTest("compiler/testData/writeFlags/property/classObject/rename/propertyAndProperty.kt");
@@ -641,16 +621,6 @@ public class WriteFlagsTestGenerated extends AbstractWriteFlagsTest {
doTest("compiler/testData/writeFlags/property/classObject/trait/delegatedPublicVal.kt");
}
@TestMetadata("extensionPublicVal.kt")
public void testExtensionPublicVal() throws Exception {
doTest("compiler/testData/writeFlags/property/classObject/trait/extensionPublicVal.kt");
}
@TestMetadata("extensionPublicVar.kt")
public void testExtensionPublicVar() throws Exception {
doTest("compiler/testData/writeFlags/property/classObject/trait/extensionPublicVar.kt");
}
@TestMetadata("internalVal.kt")
public void testInternalVal() throws Exception {
doTest("compiler/testData/writeFlags/property/classObject/trait/internalVal.kt");
@@ -2272,6 +2272,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
@TestMetadata("compiler/testData/codegen/box/extensionProperties")
public static class ExtensionProperties extends AbstractBlackBoxCodegenTest {
@TestMetadata("accessorForPrivateSetter.kt")
public void testAccessorForPrivateSetter() throws Exception {
doTest("compiler/testData/codegen/box/extensionProperties/accessorForPrivateSetter.kt");
}
public void testAllFilesPresentInExtensionProperties() throws Exception {
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.TestsPackage", new File("compiler/testData/codegen/box/extensionProperties"), Pattern.compile("^(.+)\\.kt$"), true);
}
@@ -2286,11 +2291,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest("compiler/testData/codegen/box/extensionProperties/inClassLongTypeInReceiver.kt");
}
@TestMetadata("inClassWithEmptySetter.kt")
public void testInClassWithEmptySetter() throws Exception {
doTest("compiler/testData/codegen/box/extensionProperties/inClassWithEmptySetter.kt");
}
@TestMetadata("inClassWithGetter.kt")
public void testInClassWithGetter() throws Exception {
doTest("compiler/testData/codegen/box/extensionProperties/inClassWithGetter.kt");
@@ -2321,21 +2321,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest("compiler/testData/codegen/box/extensionProperties/topLevelLongTypeInReceiver.kt");
}
@TestMetadata("topLevelSetterLongTypeInReceiver.kt")
public void testTopLevelSetterLongTypeInReceiver() throws Exception {
doTest("compiler/testData/codegen/box/extensionProperties/topLevelSetterLongTypeInReceiver.kt");
}
@TestMetadata("topLevelWithGetter.kt")
public void testTopLevelWithGetter() throws Exception {
doTest("compiler/testData/codegen/box/extensionProperties/topLevelWithGetter.kt");
}
@TestMetadata("topLevelWithSetter.kt")
public void testTopLevelWithSetter() throws Exception {
doTest("compiler/testData/codegen/box/extensionProperties/topLevelWithSetter.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/fakeOverride")
@@ -2387,16 +2372,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
doTest("compiler/testData/codegen/box/fieldRename/genericPropertyWithItself.kt");
}
@TestMetadata("inPackage.kt")
public void testInPackage() throws Exception {
doTest("compiler/testData/codegen/box/fieldRename/inPackage.kt");
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
doTest("compiler/testData/codegen/box/fieldRename/simple.kt");
}
}
@TestMetadata("compiler/testData/codegen/box/finally")
@@ -2774,11 +2774,6 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
doTestCompiledKotlin("compiler/testData/loadJava/compiledKotlin/prop/defaultAccessors/ExtVarLong.kt");
}
@TestMetadata("ExtVarLongWithSet.kt")
public void testExtVarLongWithSet() throws Exception {
doTestCompiledKotlin("compiler/testData/loadJava/compiledKotlin/prop/defaultAccessors/ExtVarLongWithSet.kt");
}
}
public static Test innerSuite() {
@@ -1252,11 +1252,6 @@ public class LazyResolveRecursiveComparingTestGenerated extends AbstractLazyReso
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadJava/compiledKotlin/prop/defaultAccessors/ExtVarLong.kt");
}
@TestMetadata("ExtVarLongWithSet.kt")
public void testExtVarLongWithSet() throws Exception {
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadJava/compiledKotlin/prop/defaultAccessors/ExtVarLongWithSet.kt");
}
}
public static Test innerSuite() {
@@ -50,28 +50,14 @@ public final class JvmAbi {
return fqName.lastSegmentIs(Name.identifier(CLASS_OBJECT_CLASS_NAME));
}
@NotNull
public static String getPropertyDelegateName(@NotNull Name name) {
return name.asString() + DELEGATED_PROPERTY_NAME_SUFFIX;
}
@NotNull
public static String getSyntheticMethodNameForAnnotatedProperty(@NotNull Name propertyName) {
return propertyName.asString() + ANNOTATED_PROPERTY_METHOD_NAME_SUFFIX;
}
@NotNull
public static String getDefaultPropertyName(@NotNull Name propertyName, boolean isDelegated, boolean isExtensionProperty) {
if (isDelegated) {
return getPropertyDelegateName(propertyName);
}
String name = propertyName.asString();
if (isExtensionProperty) {
name += "$ext";
}
return name;
public static String getDefaultFieldNameForProperty(@NotNull Name propertyName, boolean isDelegated) {
return isDelegated ? propertyName.asString() + DELEGATED_PROPERTY_NAME_SUFFIX : propertyName.asString();
}
private JvmAbi() {
+1 -1
View File
@@ -1,5 +1,5 @@
fun Int?.optint() : Unit {}
val Int?.optval : Unit = Unit.VALUE
val Int?.optval : Unit get() = Unit.VALUE
fun <T: Any, E> T.foo(<warning>x</warning> : E, y : A) : T {
y.plus(1)
+1 -1
View File
@@ -25,4 +25,4 @@ object B {
fun PairParam<<error>T</error>, <error>T</error>>() {}
class PParam<<error>T</error>, <error>T</error>> {}
val <<error>T</error>, <error>T</error>> T.fooParam : Int = 1
val <<error>T</error>, <error>T</error>> T.fooParam : Int get() = 1
@@ -21,7 +21,7 @@ object TestObject {
}
val testVal = 1
val Int.testExtVal = 1
val Int.testExtVal: Int get() = 1
val testDelVal by Delegate()
class Delegate {
@@ -1252,11 +1252,6 @@ public class LazyResolveByStubTestGenerated extends AbstractLazyResolveByStubTes
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadJava/compiledKotlin/prop/defaultAccessors/ExtVarLong.kt");
}
@TestMetadata("ExtVarLongWithSet.kt")
public void testExtVarLongWithSet() throws Exception {
doTestCheckingPrimaryConstructorsAndAccessors("compiler/testData/loadJava/compiledKotlin/prop/defaultAccessors/ExtVarLongWithSet.kt");
}
}
public static Test innerSuite() {
+1 -1
View File
@@ -36,7 +36,7 @@ native public fun String.match(regex : String) : Array<String> = js.noImpl
native public fun String.trim() : String = js.noImpl
native("length")
public val CharSequence.size: Int = js.noImpl
public val CharSequence.size: Int get() = js.noImpl
library
public fun CharSequence.length(): Int = js.noImpl
+1 -1
View File
@@ -7,7 +7,7 @@ public fun createDocument(): Document {
return js.dom.html.document.implementation.createDocument(null, null, null)
}
native public val Node.outerHTML: String = js.noImpl
native public val Node.outerHTML: String get() = js.noImpl
/** Converts the node to an XML String */
public fun Node.toXmlString(): String = this.outerHTML
@@ -11,7 +11,7 @@ fun bar(): Any? {
}
native
val Exception.message: String = noImpl
val Exception.message: String get() = noImpl
fun box(): String {
val a: String? = null
@@ -10,7 +10,7 @@ var Test.b: Int
a = c - 1
}
val Test.d: Int = 44
val Test.d: Int get() = 44
fun box(): Boolean {
val c = Test()
@@ -5,8 +5,8 @@ fun Int.foo() {
fun String.foo() {
}
val Int.bar = 1
val String.bar = 2
val Int.bar: Int get() = 1
val String.bar: Int get() = 2
fun box(): String {
val a = 43
@@ -9,8 +9,8 @@ native("\"O\"") val foo: String = noImpl
native("boo") val bar: String = noImpl
class A
native("__proto__") val Any.proto: String = noImpl
native("__proto__") val A.proto: String = noImpl
native("__proto__") val Any.proto: String get() = noImpl
native("__proto__") val A.proto: String get() = noImpl
fun actual(foo: String, native("boo") bar: String) = foo + bar
fun expected(foo: String, boo: String) = foo + boo
@@ -5,8 +5,8 @@ val PACKAGE = "Kotlin.modules.JS_TESTS.foo"
native fun eval(e: String): Any? = noImpl
class A
native val Any.__proto__: String = noImpl
native val A.__proto__: String = noImpl
native val Any.__proto__: String get() = noImpl
native val A.__proto__: String get() = noImpl
fun box(): String {
val a = A()
@@ -3,9 +3,9 @@ package foo
class T
open class A {
open val T.foo: Int = 34
open val T.foo: Int
get() {
return $foo
return 34
}
fun test(): Int {
return T().foo
@@ -13,7 +13,7 @@ open class A {
}
class B : A() {
override val T.foo: Int = 5
override val T.foo: Int get() = 5
}
@@ -2,7 +2,7 @@
package foo
native val Exception.message: String = noImpl
native val Exception.message: String get() = noImpl
public fun <T : Throwable> failsWith(block: () -> Any): T {
try {