Instantly share code, notes, and snippets.

Embed
What would you like to do?
compile errors for generic function instantiation in zig
./test.zig:2:7: error: incompatible types: 'i32' and 'f64'
a + b
^
./test.zig:6:8: note: called from here
add(a, b)
^
./test.zig:10:8: note: called from here
foo(a, b)
^
./test.zig:14:8: note: called from here
bar(f64, 123, 456)
^
./test.zig:2:5: note: type 'i32' here
a + b
^
./test.zig:2:9: note: type 'f64' here
a + b
^
fn add(a: var, b: var) -> @typeOf(a) {
a + b
}
fn foo(a: var, b: var) -> i32 {
add(a, b)
}
fn bar(comptime T: type, a: i32, b: T) -> i32 {
foo(a, b)
}
fn baz() -> i32 {
bar(f64, 123, 456)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment