From d00e93a74db4cf63f662d5d8f0a7ae0b6eb79060 Mon Sep 17 00:00:00 2001 From: Alexey Yerin Date: Wed, 2 Jul 2025 22:23:19 +0300 Subject: Use the class type for constructor returns This allows to remove a lot of redundant casts and make better use of pointer subtyping. --- cmd/hare-gi/emit.ha | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmd/hare-gi/emit.ha b/cmd/hare-gi/emit.ha index f0b513e..4a9307e 100644 --- a/cmd/hare-gi/emit.ha +++ b/cmd/hare-gi/emit.ha @@ -143,7 +143,7 @@ fn emit_class(ctx: *context, class: *gir::class) (void | io::error) = { push(ctx, class.name); for (let i = 0z; i < len(class.constructors); i += 1) { - emit_constructor(ctx, &class.constructors[i])?; + emit_constructor(ctx, &class.constructors[i], class.name)?; }; for (let i = 0z; i < len(class.methods); i += 1) { emit_method(ctx, &class.methods[i])?; @@ -354,6 +354,7 @@ fn emit_constant(ctx: *context, constant: *gir::constant) (void | io::error) = { fn emit_constructor( ctx: *context, constructor: *gir::constructor, + class_name: str = "", ) (void | io::error) = { if (is_exported(ctx, constructor.c_identifier)) { return; @@ -374,7 +375,11 @@ fn emit_constructor( emit_object(ctx, ctx.glib, "Error")?; }; fmt::fprint(ctx.current.output, ") ")?; - emit_return_value(ctx, constructor.return_value)?; + if (len(class_name) != 0) { + fmt::fprintf(ctx.current.output, "*{}", class_name)?; + } else { + emit_return_value(ctx, constructor.return_value)?; + }; fmt::fprintln(ctx.current.output, ";")?; }; -- cgit 1.3.0-6-gf8a5