| author | |
| committer | |
| log | 9d8cdb855bd20f20d00618e8bc78dcf237232537 |
| tree | 49618ab8acea16582d6feb88b716ef9f46a52745 |
| parent | db5562deb0fe193aced9498c05ccf786ca98ba05 |
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 parameters2 files changed, 22 insertions(+), 1 deletions(-)
src/Sema.zig+1-1| ... | @@ -24312,7 +24312,7 @@ fn coerceInMemoryAllowedFns( | ... | @@ -24312,7 +24312,7 @@ fn coerceInMemoryAllowedFns( |
| 24312 | 24312 | ||
| 24313 | if (dest_info.param_types.len != src_info.param_types.len) { | 24313 | if (dest_info.param_types.len != src_info.param_types.len) { |
| 24314 | return InMemoryCoercionResult{ .fn_param_count = .{ | 24314 | return InMemoryCoercionResult{ .fn_param_count = .{ |
| 24315 | .actual = dest_info.param_types.len, | 24315 | .actual = src_info.param_types.len, |
| 24316 | .wanted = dest_info.param_types.len, | 24316 | .wanted = dest_info.param_types.len, |
| 24317 | } }; | 24317 | } }; |
| 24318 | } | 24318 | } |
test/cases/compile_errors/function_type_coercion.zig created+21| ... | @@ -0,0 +1,21 @@ | ||
| 1 | fn f(_: i32) void {} | ||
| 2 | export fn wrong_param_count() void { | ||
| 3 | _ = @as(fn () void, f); | ||
| 4 | } | ||
| 5 | export fn wrong_param_type() void { | ||
| 6 | _ = @as(fn (f32) void, f); | ||
| 7 | } | ||
| 8 | export fn wrong_return_type() void { | ||
| 9 | _ = @as(fn () i32, f); | ||
| 10 | } | ||
| 11 | |||
| 12 | // error | ||
| 13 | // backend=stage2,llvm | ||
| 14 | // target=native | ||
| 15 | // | ||
| 16 | // :3:25: error: expected type 'fn() void', found 'fn(i32) void' | ||
| 17 | // :3:25: note: function with 1 parameters cannot cast into a function with 0 parameters | ||
| 18 | // :6:28: error: expected type 'fn(f32) void', found 'fn(i32) void' | ||
| 19 | // :6:28: note: parameter 0 'i32' cannot cast into 'f32' | ||
| 20 | // :9:24: error: expected type 'fn() i32', found 'fn(i32) void' | ||
| 21 | // :9:24: note: return type 'void' cannot cast into return type 'i32' | ||