I have a parameter struct with this definition:
const VmRuntimeParams = struct {
/// Base allocator for all vm allocations.
allocator: std.mem.Allocator,
/// Logs runtime errors.
errorWriter: *std.Io.Writer,
/// Used only for debugging purposes. Logs all executed opcodes and (call)stack.
traceWriter: if (compParams.hasTraces()) *std.Io.Writer else void,
/// Used for debugging. Logs all allocations calls and GC cycles.
gcWriter: if (compParams.hasMemory()) *std.Io.Writer else void,
};
And I would like to set the last two fields conditionaly:
var vm = try Vm.init(.{
.errorWriter = stderr,
.allocator = genericAllocator,
.gcWriter = if (Vm.params.hasMemory()) memoryWriterInterface else {},
.traceWriter = if (Vm.params.hasTraces()) traceWriterInterface else {},
});
Zig 0.15.1 will error at me telling me the two if branches don’t have the same type. How can I solve this ? Maybe there’s a simpler way ?