Created
December 17, 2019 14:22
-
-
Save yoh2/8925c8268cc023fff546054585297439 to your computer and use it in GitHub Desktop.
heap.create で分かりにくいエラー (std/heap.zen 中で error[E04001]: use of undefined value) が出るもの
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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