diff options
| author | Jacob Young <jacobly0@users.noreply.github.com> | 2022-10-01 11:38:33 -0400 |
|---|---|---|
| committer | Veikka Tuominen <git@vexu.eu> | 2022-10-03 13:06:49 +0300 |
| commit | 9d8cdb855bd20f20d00618e8bc78dcf237232537 (patch) | |
| tree | 49618ab8acea16582d6feb88b716ef9f46a52745 /test/cases/compile_errors | |
| parent | db5562deb0fe193aced9498c05ccf786ca98ba05 (diff) | |
| download | zig-9d8cdb855bd20f20d00618e8bc78dcf237232537.tar.gz zig-9d8cdb855bd20f20d00618e8bc78dcf237232537.zip | |
Sema: fix function paramater count mismatch note
expected type 'fn() void', found 'fn(i32) void'
function with 0 parameters cannot cast into a function with 0 parameters
=>
expected type 'fn() void', found 'fn(i32) void'
function with 1 parameters cannot cast into a function with 0 parameters
Diffstat (limited to 'test/cases/compile_errors')
| -rw-r--r-- | test/cases/compile_errors/function_type_coercion.zig | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/test/cases/compile_errors/function_type_coercion.zig b/test/cases/compile_errors/function_type_coercion.zig new file mode 100644 index 0000000000..552995304d --- /dev/null +++ b/test/cases/compile_errors/function_type_coercion.zig @@ -0,0 +1,21 @@ +fn f(_: i32) void {} +export fn wrong_param_count() void { + _ = @as(fn () void, f); +} +export fn wrong_param_type() void { + _ = @as(fn (f32) void, f); +} +export fn wrong_return_type() void { + _ = @as(fn () i32, f); +} + +// error +// backend=stage2,llvm +// target=native +// +// :3:25: error: expected type 'fn() void', found 'fn(i32) void' +// :3:25: note: function with 1 parameters cannot cast into a function with 0 parameters +// :6:28: error: expected type 'fn(f32) void', found 'fn(i32) void' +// :6:28: note: parameter 0 'i32' cannot cast into 'f32' +// :9:24: error: expected type 'fn() i32', found 'fn(i32) void' +// :9:24: note: return type 'void' cannot cast into return type 'i32' |
