Skip to content

Instantly share code, notes, and snippets.

@cgag
Last active August 25, 2018 15:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cgag/8e1d2289cfbb3c842d61ebdddf0316f7 to your computer and use it in GitHub Desktop.
Save cgag/8e1d2289cfbb3c842d61ebdddf0316f7 to your computer and use it in GitHub Desktop.
const std = @import("std");
const Food = enum {
Pretzel,
Cheese,
Cucumber,
};
pub fn main() !void {
const alloc = &std.heap.DirectAllocator.init().allocator;
const s = try std.fmt.allocPrint(alloc, "food: {}\n", Food.Cheese);
defer alloc.free(s);
var stdout = try std.io.getStdOut();
try stdout.write(s);
}
ryzen src/zig-errors » time zig build-exe main.zig && ./main
/home/cgag/bin/zig/build/lib/zig/std/fmt/index.zig:178:32: error: no member named 'Pretzel' in enum 'Food'
try formatType(@field(value, @memberName(T, field_i)), "", context, Errors, output);
^
/home/cgag/bin/zig/build/lib/zig/std/fmt/index.zig:53:35: note: called from here
try formatType(args[next_arg], fmt[0..0], context, Errors, output);
^
/home/cgag/bin/zig/build/lib/zig/std/fmt/index.zig:826:11: note: called from here
format(&size, error{}, countSize, fmt, args) catch |err| switch (err) {};
^
/home/cgag/src/zig-errors/main.zig:16:37: note: called from here
const s = try std.fmt.allocPrint(alloc, "food: {}\n", Food.Cheese);
^
/home/cgag/bin/zig/build/lib/zig/std/fmt/index.zig:178:32: error: no member named 'Pretzel' in enum 'Food'
try formatType(@field(value, @memberName(T, field_i)), "", context, Errors, output);
^
/home/cgag/bin/zig/build/lib/zig/std/fmt/index.zig:53:35: note: called from here
try formatType(args[next_arg], fmt[0..0], context, Errors, output);
^
/home/cgag/bin/zig/build/lib/zig/std/fmt/index.zig:818:15: note: called from here
try format(&context, error{BufferTooSmall}, bufPrintWrite, fmt, args);
^
/home/cgag/bin/zig/build/lib/zig/std/fmt/index.zig:828:20: note: called from here
return bufPrint(buf, fmt, args) catch |err| switch (err) {
^
/home/cgag/src/zig-errors/main.zig:16:37: note: called from here
const s = try std.fmt.allocPrint(alloc, "food: {}\n", Food.Cheese);
^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment