From 93b860e4ad3a1f97d0be8d7400f31ccc955c6383 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Mon, 18 Mar 2013 12:47:48 +0400 Subject: [PATCH] Always generate getter and setter --- .../jetbrains/jet/codegen/PropertyCodegen.java | 17 ++++++++++------- .../box/classes/delegationMethodsWithArgs.kt | 6 +++--- .../testData/codegen/box/properties/kt2655.kt | 6 +++--- .../src/kotlin/support/AbstractIterator.kt | 8 ++++---- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java index aa9076361de..971b66d33aa 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/PropertyCodegen.java @@ -120,7 +120,8 @@ public class PropertyCodegen extends GenerationStateAware { } private void generateGetter(JetNamedDeclaration p, PropertyDescriptor propertyDescriptor, JetPropertyAccessor getter) { - if (getter != null && getter.getBodyExpression() != null || isExternallyAccessible(propertyDescriptor)) { + //TODO: Now it's not enough information to properly resolve property from bytecode without generated getter and setter + //if (getter != null && getter.getBodyExpression() != null || isExternallyAccessible(propertyDescriptor)) { JvmPropertyAccessorSignature signature = typeMapper.mapGetterSignature(propertyDescriptor, kind); PropertyGetterDescriptor getterDescriptor = propertyDescriptor.getGetter(); getterDescriptor = getterDescriptor != null ? getterDescriptor : DescriptorResolver.createDefaultGetter(propertyDescriptor); @@ -129,12 +130,13 @@ public class PropertyCodegen extends GenerationStateAware { true, signature.getPropertyTypeKotlinSignature(), getterDescriptor); - } + //} } private void generateSetter(JetNamedDeclaration p, PropertyDescriptor propertyDescriptor, JetPropertyAccessor setter) { - if (setter != null && setter.getBodyExpression() != null - || isExternallyAccessible(propertyDescriptor) && propertyDescriptor.isVar()) { + //TODO: Now it's not enough information to properly resolve property from bytecode without generated getter and setter + if (/*setter != null && setter.getBodyExpression() != null + || isExternallyAccessible(propertyDescriptor) &&*/ propertyDescriptor.isVar()) { JvmPropertyAccessorSignature signature = typeMapper.mapSetterSignature(propertyDescriptor, kind); PropertySetterDescriptor setterDescriptor = propertyDescriptor.getSetter(); setterDescriptor = setterDescriptor != null ? setterDescriptor : DescriptorResolver.createDefaultSetter(propertyDescriptor); @@ -155,7 +157,7 @@ public class PropertyCodegen extends GenerationStateAware { @NotNull CodegenContext context) { PropertyDescriptor propertyDescriptor = accessorDescriptor.getCorrespondingProperty(); - final Type type = typeMapper.mapType(propertyDescriptor); + Type type = typeMapper.mapType(propertyDescriptor); if (accessorDescriptor instanceof PropertyGetterDescriptor) { if (kind != OwnerKind.NAMESPACE) { iv.load(0, OBJECT_TYPE); @@ -166,7 +168,8 @@ public class PropertyCodegen extends GenerationStateAware { propertyDescriptor.getName().getName(), type.getDescriptor()); iv.areturn(type); - } else if (accessorDescriptor instanceof PropertySetterDescriptor) { + } + else if (accessorDescriptor instanceof PropertySetterDescriptor) { int paramCode = 0; if (kind != OwnerKind.NAMESPACE) { iv.load(0, OBJECT_TYPE); @@ -184,7 +187,7 @@ public class PropertyCodegen extends GenerationStateAware { iv.visitInsn(RETURN); } else { - assert false; + assert false : "Unreachable state"; } } diff --git a/compiler/testData/codegen/box/classes/delegationMethodsWithArgs.kt b/compiler/testData/codegen/box/classes/delegationMethodsWithArgs.kt index 5e047aa7394..dc84a1ed194 100644 --- a/compiler/testData/codegen/box/classes/delegationMethodsWithArgs.kt +++ b/compiler/testData/codegen/box/classes/delegationMethodsWithArgs.kt @@ -13,10 +13,10 @@ trait MooableTextField : InputTextField { } class SimpleTextField : MooableTextField { - private var text = "" - override fun getText() = text + private var text2 = "" + override fun getText() = text2 override fun setText(text: String) { - this.text = text + this.text2 = text } override fun moo(a: Int, b: Int, c: Int) = a + b + c } diff --git a/compiler/testData/codegen/box/properties/kt2655.kt b/compiler/testData/codegen/box/properties/kt2655.kt index d3cd1337273..36244dcee3f 100644 --- a/compiler/testData/codegen/box/properties/kt2655.kt +++ b/compiler/testData/codegen/box/properties/kt2655.kt @@ -4,10 +4,10 @@ trait TextField { } class SimpleTextField : TextField { - private var text = "" - override fun getText() = text + private var text2 = "" + override fun getText() = text2 override fun setText(text: String) { - this.text = text + this.text2 = text } } diff --git a/libraries/stdlib/src/kotlin/support/AbstractIterator.kt b/libraries/stdlib/src/kotlin/support/AbstractIterator.kt index 6835dc9790a..193b5e83955 100644 --- a/libraries/stdlib/src/kotlin/support/AbstractIterator.kt +++ b/libraries/stdlib/src/kotlin/support/AbstractIterator.kt @@ -19,7 +19,7 @@ object State { */ public abstract class AbstractIterator: Iterator { private var state = State.NotReady - private var next: T? = null + private var nextValue: T? = null override fun hasNext(): Boolean { require(state != State.Failed) @@ -33,13 +33,13 @@ public abstract class AbstractIterator: Iterator { override fun next(): T { if (!hasNext()) throw NoSuchElementException() state = State.NotReady - return next as T + return nextValue as T } /** Returns the next element in the iteration without advancing the iteration */ fun peek(): T { if (!hasNext()) throw NoSuchElementException() - return next as T; + return nextValue as T; } private fun tryToComputeNext(): Boolean { @@ -64,7 +64,7 @@ public abstract class AbstractIterator: Iterator { * Sets the next value in the iteration, called from the [[computeNext()]] function */ protected fun setNext(value: T): Unit { - next = value + nextValue = value state = State.Ready }