From: Matt Corallo Date: Mon, 27 Jun 2022 18:20:45 +0000 (+0000) Subject: Use fully-qualified types more often in conversions X-Git-Tag: v0.0.108.0^2~15 X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=commitdiff_plain;h=41fd4b2fbfdaf80ed7f44df6fd4d6f64b9fc8997;p=ldk-java Use fully-qualified types more often in conversions This ensures to-human conversions still work correctly inside enums where there is an enum variant named identically to the type which is being converted to (eg in the new `GraphSyncError` enum). --- diff --git a/gen_type_mapping.py b/gen_type_mapping.py index 9aeee615..0f2babf0 100644 --- a/gen_type_mapping.py +++ b/gen_type_mapping.py @@ -337,12 +337,13 @@ class TypeMappingGenerator: to_hu_conv_sfx = "" if not ty_info.is_ptr or holds_ref: to_hu_conv_sfx = "\n" + self.consts.add_ref(ty_info.var_name + "_hu_conv", "this") + ";" + qualified_hu_ty = self.consts.fully_qualified_hu_ty_path(ty_info) if ty_info.is_ptr: return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name, arg_conv = opaque_arg_conv, arg_conv_name = "&" + ty_info.var_name + "_conv", arg_conv_cleanup = None, ret_conv = (ty_info.rust_obj + " " + ty_info.var_name + "_var = *", opaque_ret_conv_suf), ret_conv_name = ty_info.var_name + "_ref", - to_hu_conv = self.consts.to_hu_conv_templates['ptr'].replace('{human_type}', ty_info.java_hu_ty).replace('{var_name}', ty_info.var_name) + to_hu_conv_sfx, + to_hu_conv = self.consts.to_hu_conv_templates['ptr'].replace('{human_type}', qualified_hu_ty).replace('{var_name}', ty_info.var_name) + to_hu_conv_sfx, to_hu_conv_name = ty_info.var_name + "_hu_conv", from_hu_conv = from_hu_conv) else: @@ -350,7 +351,7 @@ class TypeMappingGenerator: arg_conv = opaque_arg_conv, arg_conv_name = ty_info.var_name + "_conv", arg_conv_cleanup = None, ret_conv = (ty_info.rust_obj + " " + ty_info.var_name + "_var = ", opaque_ret_conv_suf), ret_conv_name = ty_info.var_name + "_ref", - to_hu_conv = self.consts.to_hu_conv_templates['default'].replace('{human_type}', ty_info.java_hu_ty).replace('{var_name}', ty_info.var_name) + to_hu_conv_sfx, + to_hu_conv = self.consts.to_hu_conv_templates['default'].replace('{human_type}', qualified_hu_ty).replace('{var_name}', ty_info.var_name) + to_hu_conv_sfx, to_hu_conv_name = ty_info.var_name + "_hu_conv", from_hu_conv = from_hu_conv)