From 435c7e342f731086f87eac546f4f6a2e06035f9a Mon Sep 17 00:00:00 2001 From: Kegan Dougal <7190048+kegsay@users.noreply.github.com> Date: Thu, 14 Mar 2024 16:48:01 +0000 Subject: [PATCH] Also use type casts for callbacks Signed-off-by: Kegan Dougal <7190048+kegsay@users.noreply.github.com> --- bindgen/templates/CallbackInterfaceTemplate.go | 2 +- fixtures/errors/src/errors.udl | 4 ++++ fixtures/errors/src/lib.rs | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/bindgen/templates/CallbackInterfaceTemplate.go b/bindgen/templates/CallbackInterfaceTemplate.go index 6bc4a79..4e388ff 100644 --- a/bindgen/templates/CallbackInterfaceTemplate.go +++ b/bindgen/templates/CallbackInterfaceTemplate.go @@ -69,7 +69,7 @@ func ({{ foreign_callback }}) {{ method_name }} (callback {{ type_name }}, args {%- endmatch -%} callback.{{ meth.name()|fn_name }}( {%- for arg in meth.arguments() -%} - {{ arg|read_fn }}(reader) + {{ arg|read_fn }}(reader){{arg|error_type_cast}} {%- if !loop.last %}, {% endif -%} {%- endfor -%} ); diff --git a/fixtures/errors/src/errors.udl b/fixtures/errors/src/errors.udl index 6c1d839..0230101 100644 --- a/fixtures/errors/src/errors.udl +++ b/fixtures/errors/src/errors.udl @@ -51,6 +51,10 @@ dictionary Vec2 { double y; }; +callback interface Callback { + void do_something(BoobyTrapError error); +}; + namespace errors { [Throws=BoobyTrapError] diff --git a/fixtures/errors/src/lib.rs b/fixtures/errors/src/lib.rs index 91ccf79..9172868 100644 --- a/fixtures/errors/src/lib.rs +++ b/fixtures/errors/src/lib.rs @@ -57,6 +57,10 @@ pub struct Vec2 { y: f64, } +pub trait Callback { + fn do_something(&self, error: BoobyTrapError); +} + impl Vec2 { pub fn new(x: f64, y: f64) -> Vec2 { Vec2 { x, y }