ability to specify function type

closes #14
This commit is contained in:
Andrew Kelley
2016-01-28 20:26:40 -07:00
parent 2bb2e61ee2
commit a5c2de5fee
5 changed files with 170 additions and 70 deletions

View File

@@ -1866,6 +1866,23 @@ fn f(i32) {}
)SOURCE", 2,
".tmp_source.zig:2:1: error: missing function name",
".tmp_source.zig:3:6: error: missing parameter name");
add_compile_fail_case("wrong function type", R"SOURCE(
const fns = []fn(){ a, b, c };
fn a() -> i32 {0}
fn b() -> i32 {1}
fn c() -> i32 {2}
)SOURCE", 3,
".tmp_source.zig:2:21: error: expected type 'fn()', got 'fn() -> i32'",
".tmp_source.zig:2:24: error: expected type 'fn()', got 'fn() -> i32'",
".tmp_source.zig:2:27: error: expected type 'fn()', got 'fn() -> i32'");
add_compile_fail_case("extern function pointer mismatch", R"SOURCE(
const fns = [](fn(i32)->i32){ a, b, c };
pub fn a(x: i32) -> i32 {x + 0}
pub fn b(x: i32) -> i32 {x + 1}
export fn c(x: i32) -> i32 {x + 2}
)SOURCE", 1, ".tmp_source.zig:2:37: error: expected type 'fn(i32) -> i32', got 'extern fn(i32) -> i32'");
}
//////////////////////////////////////////////////////////////////////////////