Skip to content

Commit 8fd7cc1

Browse files
committedJun 18, 2018
disallow opaque as a return type of fn type syntax
closes #1115
·
0.15.20.3.0
1 parent d49d6f0 commit 8fd7cc1

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed
 

‎src/analyze.cpp‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
const tests = @import("tests.zig");
22

33
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+
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 {

0 commit comments

Comments
 (0)
Please sign in to comment.