From 9a4790947202c4e732c68c7c3be9b8643e8080b0 Mon Sep 17 00:00:00 2001 From: Ellen Arteca Date: Wed, 13 Nov 2024 15:24:39 -0800 Subject: [PATCH] Fix cookie creation for trait struct in Kotlin --- .../main/kotlin/dev/diplomattest/somelib/TesterTrait.kt | 5 +++-- .../snapshots/diplomat_tool__kotlin__test__trait_gen.snap | 7 ++++--- tool/templates/kotlin/Trait.kt.jinja | 5 +++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/feature_tests/kotlin/somelib/src/main/kotlin/dev/diplomattest/somelib/TesterTrait.kt b/feature_tests/kotlin/somelib/src/main/kotlin/dev/diplomattest/somelib/TesterTrait.kt index cd8ff0ea1..eb66bee4f 100644 --- a/feature_tests/kotlin/somelib/src/main/kotlin/dev/diplomattest/somelib/TesterTrait.kt +++ b/feature_tests/kotlin/somelib/src/main/kotlin/dev/diplomattest/somelib/TesterTrait.kt @@ -109,8 +109,9 @@ internal class DiplomatTrait_TesterTrait_Wrapper internal constructor ( vtable.run_testStructTraitFn_callback = testStructTraitFn; val native_wrapper = DiplomatTrait_TesterTrait_Wrapper_Native(); native_wrapper.vtable = vtable; - native_wrapper.data_ = DiplomatJVMRuntime.buildRustCookie(native_wrapper as Object); - return DiplomatTrait_TesterTrait_Wrapper(native_wrapper); + val ret_val = DiplomatTrait_TesterTrait_Wrapper(native_wrapper); + ret_val.nativeStruct.data_ = DiplomatJVMRuntime.buildRustCookie(ret_val as Object); + return ret_val; } } } diff --git a/tool/src/kotlin/snapshots/diplomat_tool__kotlin__test__trait_gen.snap b/tool/src/kotlin/snapshots/diplomat_tool__kotlin__test__trait_gen.snap index 7738f91f4..917679eab 100644 --- a/tool/src/kotlin/snapshots/diplomat_tool__kotlin__test__trait_gen.snap +++ b/tool/src/kotlin/snapshots/diplomat_tool__kotlin__test__trait_gen.snap @@ -1,6 +1,6 @@ --- source: tool/src/kotlin/mod.rs -assertion_line: 2424 +assertion_line: 2422 expression: result --- package dev.gigapixel.somelib @@ -168,8 +168,9 @@ internal class DiplomatTrait_TesterTrait_Wrapper internal constructor ( vtable.run_testEnumReturn_callback = testEnumReturn; val native_wrapper = DiplomatTrait_TesterTrait_Wrapper_Native(); native_wrapper.vtable = vtable; - native_wrapper.data_ = DiplomatJVMRuntime.buildRustCookie(native_wrapper as Object); - return DiplomatTrait_TesterTrait_Wrapper(native_wrapper); + val ret_val = DiplomatTrait_TesterTrait_Wrapper(native_wrapper); + ret_val.nativeStruct.data_ = DiplomatJVMRuntime.buildRustCookie(ret_val as Object); + return ret_val; } } } diff --git a/tool/templates/kotlin/Trait.kt.jinja b/tool/templates/kotlin/Trait.kt.jinja index a98b2670f..f061100dc 100644 --- a/tool/templates/kotlin/Trait.kt.jinja +++ b/tool/templates/kotlin/Trait.kt.jinja @@ -100,8 +100,9 @@ internal class DiplomatTrait_{{trait_name}}_Wrapper internal constructor ( {% endif -%} val native_wrapper = DiplomatTrait_{{trait_name}}_Wrapper_Native(); native_wrapper.vtable = vtable; - native_wrapper.data_ = DiplomatJVMRuntime.buildRustCookie(native_wrapper as Object); - return DiplomatTrait_{{trait_name}}_Wrapper(native_wrapper); + val ret_val = DiplomatTrait_{{trait_name}}_Wrapper(native_wrapper); + ret_val.nativeStruct.data_ = DiplomatJVMRuntime.buildRustCookie(ret_val as Object); + return ret_val; } } }