Skip to content

Commit

Permalink
fixing the same bug for other modified primitive results (#693)
Browse files Browse the repository at this point in the history
Co-authored-by: Ellen Arteca <[email protected]>
  • Loading branch information
emarteca and Ellen Arteca authored Sep 17, 2024
1 parent c3bf8e3 commit 7dc0d8e
Show file tree
Hide file tree
Showing 11 changed files with 35 additions and 25 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 5 additions & 6 deletions tool/src/kotlin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,12 +695,7 @@ return string{return_type_modifier}"#
match o {
Type::Primitive(prim) => {
let maybe_unsized_modifier = self.formatter.fmt_unsized_conversion(*prim, false);
match prim {
PrimitiveType::Bool => {
format!("return ({val_name}{maybe_unsized_modifier}){return_type_modifier}")
}
_ => format!("return {val_name}{return_type_modifier}{maybe_unsized_modifier}"),
}
format!("return ({val_name}{maybe_unsized_modifier}){return_type_modifier}")
}
Type::Opaque(opaque_path) => self.gen_opaque_return_conversion(
opaque_path,
Expand Down Expand Up @@ -2031,6 +2026,10 @@ mod test {
pub fn boolean_result() -> Result<bool, ()> {
todo!()
}

pub fn ubyte_result() -> Result<u8, ()> {
todo!()
}
}
}
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: tool/src/kotlin/mod.rs
assertion_line: 2042
assertion_line: 2261
expression: result
---
package dev.gigapixel.somelib;
Expand Down Expand Up @@ -37,13 +37,13 @@ class MyOpaqueStruct internal constructor (
fun getByte(): UByte {

val returnVal = lib.MyOpaqueStruct_get_byte();
return returnVal.toUByte()
return (returnVal.toUByte())
}

fun getStringWrapper(in1: Int): Int {

val returnVal = lib.MyOpaqueStruct_get_string_wrapper(in1);
return returnVal
return (returnVal)
}
}

Expand Down
15 changes: 13 additions & 2 deletions tool/src/kotlin/snapshots/diplomat_tool__kotlin__test__struct.snap
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
source: tool/src/kotlin/mod.rs
assertion_line: 2057
assertion_line: 2058
expression: struct_code
---
package dev.gigapixel.somelib
Expand All @@ -16,6 +16,7 @@ internal interface MyNativeStructLib: Library {
fun MyNativeStruct_test_multi_arg_callback(f: DiplomatCallback_MyNativeStruct_test_multi_arg_callback_diplomatCallback_f_Native, x: Int): Int
fun MyNativeStruct_get_u_byte_slice(): Slice
fun MyNativeStruct_boolean_result(): ResultByteUnit
fun MyNativeStruct_ubyte_result(): ResultByteUnit
}

internal class MyNativeStructNative: Structure(), Structure.ByValue {
Expand Down Expand Up @@ -140,7 +141,7 @@ class MyNativeStruct internal constructor (
fun testMultiArgCallback(f: (Int)->Int, x: Int): Int {

val returnVal = lib.MyNativeStruct_test_multi_arg_callback(DiplomatCallback_MyNativeStruct_test_multi_arg_callback_diplomatCallback_f.fromCallback(f).nativeStruct, x);
return returnVal
return (returnVal)
}

fun getUByteSlice(): UByteArray {
Expand All @@ -158,6 +159,16 @@ class MyNativeStruct internal constructor (
return Err(Unit)
}
}

fun ubyteResult(): Res<UByte, Unit> {

val returnVal = lib.MyNativeStruct_ubyte_result();
if (returnVal.isOk == 1.toByte()) {
return (returnVal.union.ok.toUByte()).ok()
} else {
return Err(Unit)
}
}
}

}

0 comments on commit 7dc0d8e

Please sign in to comment.