authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-14 16:24:43-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-02-14 16:24:43-05:00
log9fa35adbd4772f55e3e43dd7cc69823415661153
tree3b678df3295a336401543d072d5d7e01ba26aed7
parent629f134d3805f99938f59a6ee7f6598591abc9d7

fix sometimes not type checking function parameters

closes #774 regression introduced in cfb2c676925d77887e46631dcafa783e6c65e61d

2 files changed, 14 insertions(+), 1 deletions(-)

src/ir.cpp+1-1
...@@ -6727,8 +6727,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry...@@ -6727,8 +6727,8 @@ static ConstCastOnly types_match_const_cast_only(IrAnalyze *ira, TypeTableEntry
6727 result.id = ConstCastResultIdFnReturnType;6727 result.id = ConstCastResultIdFnReturnType;
6728 result.data.return_type = allocate_nonzero<ConstCastOnly>(1);6728 result.data.return_type = allocate_nonzero<ConstCastOnly>(1);
6729 *result.data.return_type = child;6729 *result.data.return_type = child;
6730 return result;
6730 }6731 }
6731 return result;
6732 }6732 }
6733 if (expected_type->data.fn.fn_type_id.param_count != actual_type->data.fn.fn_type_id.param_count) {6733 if (expected_type->data.fn.fn_type_id.param_count != actual_type->data.fn.fn_type_id.param_count) {
6734 result.id = ConstCastResultIdFnArgCount;6734 result.id = ConstCastResultIdFnArgCount;
test/compile_errors.zig+13
...@@ -1,6 +1,19 @@...@@ -1,6 +1,19 @@
1const tests = @import("tests.zig");1const tests = @import("tests.zig");
22
3pub fn addCases(cases: &tests.CompileErrorContext) void {3pub fn addCases(cases: &tests.CompileErrorContext) void {
4 cases.add("type checking function pointers",
5 \\fn a(b: fn (&const u8) void) void {
6 \\ b('a');
7 \\}
8 \\fn c(d: u8) void {
9 \\ @import("std").debug.warn("{c}\n", d);
10 \\}
11 \\export fn entry() void {
12 \\ a(c);
13 \\}
14 ,
15 ".tmp_source.zig:8:7: error: expected type 'fn(&const u8) void', found 'fn(u8) void'");
16
4 cases.add("no else prong on switch on global error set",17 cases.add("no else prong on switch on global error set",
5 \\export fn entry() void {18 \\export fn entry() void {
6 \\ foo(error.A);19 \\ foo(error.A);