Skip to content

Commit

Permalink
Merge pull request #2748 from ghostty-org/push-zzqzxrsnqrtn
Browse files Browse the repository at this point in the history
cli: parseCLI for optionals should not be null in release modes
  • Loading branch information
mitchellh authored Nov 21, 2024
2 parents d3b2f33 + 4ef2240 commit 63bf16f
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/cli/args.zig
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,20 @@ pub fn parseIntoField(
.Enum,
=> try @field(dst, field.name).parseCLI(value),

.Optional => {
@field(dst, field.name) = undefined;
try @field(dst, field.name).?.parseCLI(value);
// If the field is optional and set, then we use
// the pointer value directly into it. If its not
// set we need to create a new instance.
.Optional => if (@field(dst, field.name)) |*v| {
try v.parseCLI(value);
} else {
// Note: you cannot do @field(dst, name) = undefined
// because this causes the value to be "null"
// in ReleaseFast modes.
var tmp: Field = undefined;
try tmp.parseCLI(value);
@field(dst, field.name) = tmp;
},

else => @compileError("unexpected field type"),
},

Expand All @@ -270,10 +280,14 @@ pub fn parseIntoField(
.Enum,
=> try @field(dst, field.name).parseCLI(alloc, value),

.Optional => {
@field(dst, field.name) = undefined;
try @field(dst, field.name).?.parseCLI(alloc, value);
.Optional => if (@field(dst, field.name)) |*v| {
try v.parseCLI(alloc, value);
} else {
var tmp: Field = undefined;
try tmp.parseCLI(alloc, value);
@field(dst, field.name) = tmp;
},

else => @compileError("unexpected field type"),
},

Expand Down

0 comments on commit 63bf16f

Please sign in to comment.