From: Matt Corallo Date: Sun, 8 Oct 2023 05:53:25 +0000 (+0000) Subject: Update args on supertraits of supertraits when cloning trait impls X-Git-Tag: v0.0.117.1^2~1 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=6c7a4f5ecc7b225d480d5b5dc021af0a59430ad4;p=ldk-c-bindings Update args on supertraits of supertraits when cloning trait impls When cloning implementations of traits from in-crate structs, we forgot to update the arguments for supertraits of supertraits, causing methods on that trait to be called against the previous struct, not the cloned one. This was ultimately identified downstream in the Java bindings, fixes https://github.com/lightningdevkit/ldk-garbagecollected/issues/138 --- diff --git a/c-bindings-gen/src/main.rs b/c-bindings-gen/src/main.rs index c00b32d..22eabf7 100644 --- a/c-bindings-gen/src/main.rs +++ b/c-bindings-gen/src/main.rs @@ -1254,15 +1254,22 @@ fn writeln_impl(w: &mut W, w_uses: &mut HashSet { - if types.crate_types.traits.get(s).is_some() { - assert!(!types.is_clonable(s)); // We don't currently support cloning with a clonable supertrait - writeln!(w, "\tnew_obj.{}.this_arg = new_obj.this_arg;", t).unwrap(); - writeln!(w, "\tnew_obj.{}.free = None;", t).unwrap(); + + fn seek_supertraits(w: &mut W, pfx: &str, tr: &syn::ItemTrait, types: &TypeResolver) { + walk_supertraits!(tr, Some(types), ( + (s, t, _) => { + if types.crate_types.traits.get(s).is_some() { + assert!(!types.is_clonable(s)); // We don't currently support cloning with a clonable supertrait + writeln!(w, "\tnew_obj.{}{}.this_arg = new_obj.this_arg;", pfx, t).unwrap(); + writeln!(w, "\tnew_obj.{}{}.free = None;", pfx, t).unwrap(); + let tr = types.crate_types.traits.get(s).unwrap(); + let resolver = get_module_type_resolver!(s, types.crate_types); + seek_supertraits(w, &format!("{}.", t), tr, &resolver); + } } - } - ) ); + ) ); + } + seek_supertraits(w, "", trait_obj, types); writeln!(w, "}}").unwrap(); } write!(w, "\n").unwrap();