diff options
author | Alexey Yerin <yyp@disroot.org> | 2025-07-02 22:23:19 +0300 |
---|---|---|
committer | Alexey Yerin <yyp@disroot.org> | 2025-07-02 22:23:19 +0300 |
commit | d00e93a74db4cf63f662d5d8f0a7ae0b6eb79060 (patch) | |
tree | 53bf105dd41dcfd5e5f43d0f3207eebd8f3050f2 | |
parent | 88e9de918413e10086455bc08946b6f9d979f735 (diff) |
Use the class type for constructor returns
This allows to remove a lot of redundant casts and make better use of pointer subtyping.
-rw-r--r-- | cmd/hare-gi/emit.ha | 9 |
1 files 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, ";")?; }; |