authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-18 11:12:15-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-18 11:12:15-04:00
log8fd7cc11e167c0b23892d6f22841bb6856d0f499
tree75b306d787fbbafb07ec840ef20cff1fe954e087
parentd49d6f0cde782f4ec3c1d623d58644c3e51a6ce9

disallow opaque as a return type of fn type syntax

closes #1115

3 files changed, 16 insertions(+), 0 deletions(-)

src/analyze.cpp+1
......@@ -1022,6 +1022,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
10221022 ensure_complete_type(g, fn_type_id->return_type);
10231023 if (type_is_invalid(fn_type_id->return_type))
10241024 return g->builtin_types.entry_invalid;
1025 assert(fn_type_id->return_type->id != TypeTableEntryIdOpaque);
10251026 } else {
10261027 zig_panic("TODO implement inferred return types https://github.com/ziglang/zig/issues/447");
10271028 }
src/ir.cpp+5
......@@ -18676,6 +18676,11 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc
1867618676 fn_type_id.return_type = ir_resolve_type(ira, return_type_value);
1867718677 if (type_is_invalid(fn_type_id.return_type))
1867818678 return ira->codegen->builtin_types.entry_invalid;
18679 if (fn_type_id.return_type->id == TypeTableEntryIdOpaque) {
18680 ir_add_error(ira, instruction->return_type,
18681 buf_sprintf("return type cannot be opaque"));
18682 return ira->codegen->builtin_types.entry_invalid;
18683 }
1867918684
1868018685 if (fn_type_id.cc == CallingConventionAsync) {
1868118686 if (instruction->async_allocator_type_value == nullptr) {
test/compile_errors.zig+10
......@@ -1,6 +1,15 @@
11const tests = @import("tests.zig");
22
33pub fn addCases(cases: *tests.CompileErrorContext) void {
4 cases.add(
5 "use c_void as return type of fn ptr",
6 \\export fn entry() void {
7 \\ const a: fn () c_void = undefined;
8 \\}
9 ,
10 ".tmp_source.zig:2:20: error: return type cannot be opaque",
11 );
12
413 cases.add(
514 "non int passed to @intToFloat",
615 \\export fn entry() void {
......@@ -9,6 +18,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
918 ,
1019 ".tmp_source.zig:2:32: error: expected int type, found 'comptime_float'",
1120 );
21
1222 cases.add(
1323 "use implicit casts to assign null to non-nullable pointer",
1424 \\export fn entry() void {