diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ClassBodyCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ClassBodyCodegen.java index 5744d0adeba..6c9083f4098 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ClassBodyCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ClassBodyCodegen.java @@ -112,7 +112,14 @@ public abstract class ClassBodyCodegen { //noinspection ConstantConditions if (!(kind instanceof OwnerKind.DelegateKind) && state.getBindingContext().get(BindingContext.BACKING_FIELD_REQUIRED, propertyDescriptor)) { - v.newField(p, Opcodes.ACC_PRIVATE, p.getName(), state.getTypeMapper().mapType(propertyDescriptor.getOutType()).getDescriptor(), null, null); + int modifiers = JetTypeMapper.getAccessModifiers(propertyDescriptor, 0); + if (!propertyDescriptor.isVar()) { + modifiers |= Opcodes.ACC_FINAL; + } + if(state.getStandardLibrary().isVolatile(propertyDescriptor)) { + modifiers |= Opcodes.ACC_VOLATILE; + } + v.newField(p, modifiers, p.getName(), state.getTypeMapper().mapType(propertyDescriptor.getOutType()).getDescriptor(), null, null); } } } diff --git a/compiler/testData/codegen/regressions/kt1398.kt b/compiler/testData/codegen/regressions/kt1398.kt new file mode 100644 index 00000000000..791b724b229 --- /dev/null +++ b/compiler/testData/codegen/regressions/kt1398.kt @@ -0,0 +1,7 @@ +open class Base(val bar: String) + +class Foo(bar: String) : Base(bar) { + fun something() = (bar as java.lang.String).toUpperCase() +} + +fun box() = Foo("ok").something() \ No newline at end of file diff --git a/compiler/testData/codegen/regressions/kt1417.kt b/compiler/testData/codegen/regressions/kt1417.kt new file mode 100644 index 00000000000..01a76072892 --- /dev/null +++ b/compiler/testData/codegen/regressions/kt1417.kt @@ -0,0 +1,9 @@ +package pack + +open class A(val value: String ) + +class B(value: String) : A(value) { + fun toString() = "B($value)"; +} + +fun box() = if (B("4").toString() == "B(4)") "OK" else "fail" \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/codegen/PropertyGenTest.java b/compiler/tests/org/jetbrains/jet/codegen/PropertyGenTest.java index 5fa1d02901f..99f22f965e3 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/PropertyGenTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/PropertyGenTest.java @@ -205,4 +205,12 @@ public class PropertyGenTest extends CodegenTestCase { public void testKt1159() throws Exception { blackBoxFile("regressions/kt1159.kt"); } + + public void testKt1417() throws Exception { + blackBoxFile("regressions/kt1417.kt"); + } + + public void testKt1398() throws Exception { + blackBoxFile("regressions/kt1398.kt"); + } }