| author | |
| committer | |
| log | 8fd7cc11e167c0b23892d6f22841bb6856d0f499 |
| tree | 75b306d787fbbafb07ec840ef20cff1fe954e087 |
| parent | d49d6f0cde782f4ec3c1d623d58644c3e51a6ce9 |
closes #11153 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 | 1022 | ensure_complete_type(g, fn_type_id->return_type); |
| 1023 | 1023 | if (type_is_invalid(fn_type_id->return_type)) |
| 1024 | 1024 | return g->builtin_types.entry_invalid; |
| 1025 | assert(fn_type_id->return_type->id != TypeTableEntryIdOpaque); | |
| 1025 | 1026 | } else { |
| 1026 | 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 | 18676 | fn_type_id.return_type = ir_resolve_type(ira, return_type_value); |
| 18677 | 18677 | if (type_is_invalid(fn_type_id.return_type)) |
| 18678 | 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 | } | |
| 18679 | 18684 | |
| 18680 | 18685 | if (fn_type_id.cc == CallingConventionAsync) { |
| 18681 | 18686 | if (instruction->async_allocator_type_value == nullptr) { |
test/compile_errors.zig+10| ... | ... | @@ -1,6 +1,15 @@ |
| 1 | 1 | const tests = @import("tests.zig"); |
| 2 | 2 | |
| 3 | 3 | pub 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 | 13 | cases.add( |
| 5 | 14 | "non int passed to @intToFloat", |
| 6 | 15 | \\export fn entry() void { |
| ... | ... | @@ -9,6 +18,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void { |
| 9 | 18 | , |
| 10 | 19 | ".tmp_source.zig:2:32: error: expected int type, found 'comptime_float'", |
| 11 | 20 | ); |
| 21 | ||
| 12 | 22 | cases.add( |
| 13 | 23 | "use implicit casts to assign null to non-nullable pointer", |
| 14 | 24 | \\export fn entry() void { |