From 4543413491078c53d24115c5229989cda05cb1a5 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 7 Nov 2017 03:22:27 -0500 Subject: std.io: introduce buffered I/O and change API I started working on #465 and made some corresponding std.io API changes. New structs: * std.io.FileInStream * std.io.FileOutStream * std.io.BufferedOutStream * std.io.BufferedInStream Removed: * std.io.File.in_stream * std.io.File.out_stream Now instead of &file.out_stream or &file.in_stream to get access to the stream API for a file, you get it like this: var file_in_stream = io.FileInStream.init(&file); const in_stream = &file_in_stream.stream; var file_out_stream = io.FileOutStream.init(&file); const out_stream = &file_out_stream.stream; This is evidence that we might not need any OOP features - See #130. --- src/ir.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/ir.cpp') diff --git a/src/ir.cpp b/src/ir.cpp index ae48c1d369..1d63677024 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -12823,6 +12823,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira, case TypeTableEntryIdEnum: { TypeTableEntry *tag_type = target_type->data.enumeration.tag_type; + assert(tag_type != nullptr); if (pointee_val) { ConstExprValue *out_val = ir_build_const_from(ira, &switch_target_instruction->base); bigint_init_unsigned(&out_val->data.x_bigint, pointee_val->data.x_enum.tag); -- cgit v1.2.3 From 7ea669e04c9314f17ce296c7521ffec2ff8575e9 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Thu, 9 Nov 2017 11:30:39 -0500 Subject: fix parameter of extern var args not type checked closes #601 --- src/ir.cpp | 11 ++++++++++- test/compile_errors.zig | 8 ++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) (limited to 'src/ir.cpp') diff --git a/src/ir.cpp b/src/ir.cpp index 1d63677024..901ba47b76 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -10311,8 +10311,17 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal { FnTypeId *fn_type_id = &fn_type->data.fn.fn_type_id; size_t first_arg_1_or_0 = first_arg_ptr ? 1 : 0; - size_t var_args_1_or_0 = fn_type_id->is_var_args ? 1 : 0; + + // for extern functions, the var args argument is not counted. + // for zig functions, it is. + size_t var_args_1_or_0; + if (fn_type_id->cc == CallingConventionUnspecified) { + var_args_1_or_0 = fn_type_id->is_var_args ? 1 : 0; + } else { + var_args_1_or_0 = 0; + } size_t src_param_count = fn_type_id->param_count - var_args_1_or_0; + size_t call_param_count = call_instruction->arg_count + first_arg_1_or_0; AstNode *source_node = call_instruction->base.source_node; diff --git a/test/compile_errors.zig b/test/compile_errors.zig index b2bfb9b8e4..fa90661158 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -2335,4 +2335,12 @@ pub fn addCases(cases: &tests.CompileErrorContext) { \\const Foo = enum {}; , ".tmp_source.zig:2:26: error: member index 0 out of bounds; 'Foo' has 0 members"); + + cases.add("calling var args extern function, passing array instead of pointer", + \\export fn entry() { + \\ foo("hello"); + \\} + \\pub extern fn foo(format: &const u8, ...); + , + ".tmp_source.zig:2:9: error: expected type '&const u8', found '[5]u8'"); } -- cgit v1.2.3