From 1c878e484396d1ab8d46ee3edef3ae82061a440e Mon Sep 17 00:00:00 2001 From: Nikolay Igotti Date: Fri, 20 Jan 2017 13:31:01 +0300 Subject: [PATCH] Improve object init order. (#187) --- backend.native/tests/build.gradle | 5 +++++ backend.native/tests/runtime/basic/initializers5.kt | 8 ++++++++ runtime/src/main/cpp/Memory.cpp | 2 +- 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 backend.native/tests/runtime/basic/initializers5.kt diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index 55147a82d03..33cb0df9721 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -834,6 +834,11 @@ task initializers4(type: RunKonanTest) { source = "runtime/basic/initializers4.kt" } +task initializers5(type: RunKonanTest) { + goldValue = "42\n" + source = "runtime/basic/initializers5.kt" +} + task expression_as_statement(type: RunKonanTest) { goldValue = "Ok\n" source = "codegen/basics/expression_as_statement.kt" diff --git a/backend.native/tests/runtime/basic/initializers5.kt b/backend.native/tests/runtime/basic/initializers5.kt new file mode 100644 index 00000000000..1c801347fee --- /dev/null +++ b/backend.native/tests/runtime/basic/initializers5.kt @@ -0,0 +1,8 @@ +object A { + val a = 42 + val b = A.a +} + +fun main(args : Array) { + println(A.b) +} \ No newline at end of file diff --git a/runtime/src/main/cpp/Memory.cpp b/runtime/src/main/cpp/Memory.cpp index c8da8601f31..7c37af313fb 100644 --- a/runtime/src/main/cpp/Memory.cpp +++ b/runtime/src/main/cpp/Memory.cpp @@ -440,9 +440,9 @@ OBJ_GETTER(InitInstance, AllocInstance(type_info, hint, OBJ_RESULT); ObjHeader* object = *OBJ_RESULT; + UpdateGlobalRef(location, object); try { ctor(object); - UpdateGlobalRef(location, object); #if CONCURRENT // TODO: locking or smth lock-free in MT case? #endif