Emit functions accepting optional object pointers

The previous code would always generate this:

  .{ o = @ptrCast(*common.Object, argument) },

That fails if `argument` is optional, with this change, it generates
this instead:

  .{ o = if (argument) |o| @ptrCast(*common.Object, o) else null },
This commit is contained in:
Reiner Gerecke
2020-10-18 11:06:18 +02:00
committed by Isaac Freund
parent 1c52af0b46
commit fbb211dff4
+9 -3
View File
@@ -309,9 +309,15 @@ const Message = struct {
},
.object, .new_id => |new_iface| {
if (arg.kind == .object or target == .server) {
try writer.writeAll(".{ .o = @ptrCast(*common.Object, ");
try printIdentifier(writer, arg.name);
try writer.writeAll(") },");
if (arg.allow_null) {
try writer.writeAll(".{ .o = if (");
try printIdentifier(writer, arg.name);
try writer.writeAll(") |o| @ptrCast(*common.Object, o) else null },");
} else {
try writer.writeAll(".{ .o = @ptrCast(*common.Object, ");
try printIdentifier(writer, arg.name);
try writer.writeAll(") },");
}
} else {
if (new_iface == null) {
try writer.writeAll(