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) {...@@ -1022,6 +1022,7 @@ TypeTableEntry *get_fn_type(CodeGen *g, FnTypeId *fn_type_id) {
1022 ensure_complete_type(g, fn_type_id->return_type);1022 ensure_complete_type(g, fn_type_id->return_type);
1023 if (type_is_invalid(fn_type_id->return_type))1023 if (type_is_invalid(fn_type_id->return_type))
1024 return g->builtin_types.entry_invalid;1024 return g->builtin_types.entry_invalid;
1025 assert(fn_type_id->return_type->id != TypeTableEntryIdOpaque);
1025 } else {1026 } else {
1026 zig_panic("TODO implement inferred return types https://github.com/ziglang/zig/issues/447");1027 zig_panic("TODO implement inferred return types https://github.com/ziglang/zig/issues/447");
1027 }1028 }
src/ir.cpp+5
...@@ -18676,6 +18676,11 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc...@@ -18676,6 +18676,11 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc
18676 fn_type_id.return_type = ir_resolve_type(ira, return_type_value);18676 fn_type_id.return_type = ir_resolve_type(ira, return_type_value);
18677 if (type_is_invalid(fn_type_id.return_type))18677 if (type_is_invalid(fn_type_id.return_type))
18678 return ira->codegen->builtin_types.entry_invalid;18678 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
18680 if (fn_type_id.cc == CallingConventionAsync) {18685 if (fn_type_id.cc == CallingConventionAsync) {
18681 if (instruction->async_allocator_type_value == nullptr) {18686 if (instruction->async_allocator_type_value == nullptr) {
test/compile_errors.zig+10
...@@ -1,6 +1,15 @@...@@ -1,6 +1,15 @@
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(
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
4 cases.add(13 cases.add(
5 "non int passed to @intToFloat",14 "non int passed to @intToFloat",
6 \\export fn entry() void {15 \\export fn entry() void {
...@@ -9,6 +18,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -9,6 +18,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
9 ,18 ,
10 ".tmp_source.zig:2:32: error: expected int type, found 'comptime_float'",19 ".tmp_source.zig:2:32: error: expected int type, found 'comptime_float'",
11 );20 );
21
12 cases.add(22 cases.add(
13 "use implicit casts to assign null to non-nullable pointer",23 "use implicit casts to assign null to non-nullable pointer",
14 \\export fn entry() void {24 \\export fn entry() void {