Skip to content

Instantly share code, notes, and snippets.

@yoh2
Created December 17, 2019 14:22
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 yoh2/8925c8268cc023fff546054585297439 to your computer and use it in GitHub Desktop.
Save yoh2/8925c8268cc023fff546054585297439 to your computer and use it in GitHub Desktop.
heap.create で分かりにくいエラー (std/heap.zen 中で error[E04001]: use of undefined value) が出るもの
const std = @import("std");
const heap = std.heap;
var buffer: [4096]u8 = undefined;
var allocator = heap.FixedBufferAllocator{ .buffer = &buffer };
fn Node(comptime T: type) type {
return struct {
next: ?*Node(T),
data: T,
};
}
fn newNode(data: var) heap.Allocator.Error!*Node(@typeOf(data)) {
var node = try heap.create(&allocator, Node(@typeOf(data)));
node.next = null;
node.data = data;
return node;
}
pub fn main() anyerror!void {
// var node = newNode(@is(i32, 10)); // これなら OK
var node = newNode(10); // .../std/heap.zen:121:56: error[E04001]: use of undefined value
std.debug.warn("{}\n", node);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment