Skip to content

Instantly share code, notes, and snippets.

@BraedonWooding
Last active April 4, 2018 14:20
Show Gist options
  • Save BraedonWooding/2758d8c0979345c9f90ad02a3db9f219 to your computer and use it in GitHub Desktop.
Save BraedonWooding/2758d8c0979345c9f90ad02a3db9f219 to your computer and use it in GitHub Desktop.
fn foo(array: []const i32, other: []const i32)bool {
warn("TEST");
return true;
}
fn other(array: []const u8, other: []const u8)bool {
warn("TEST");
return true;
}
fn k(comptime T: type, func: fn(array: T, other: T)bool, array: T) void {
warn("FOO");
_ = func(array, array);
}
test "Test" {
var array = []i32 { 0, 1, 2};
k([]i32, foo, array[0..]);
var str = "BOOOO";
// This line won't compile
k([]u8, other, str);
}
@andrewrk
Copy link

andrewrk commented Apr 4, 2018

You can't cast a [5]i32 to []i32. You have to slice it, like you do on line 18. You can only implicitly cast [5]i32 to []const i32.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment