Skip to content

Commit

Permalink
add compile error for @frame() of generic function
Browse files Browse the repository at this point in the history
See #3063
  • Loading branch information
andrewrk committed Aug 16, 2019
1 parent 49c88e2 commit 1254a45
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/analyze.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5197,6 +5197,8 @@ static Error resolve_async_frame(CodeGen *g, ZigType *frame_type) {
return ErrorNone;

ZigFn *fn = frame_type->data.frame.fn;
assert(!fn->type_entry->data.fn.is_generic);

switch (fn->anal_state) {
case FnAnalStateInvalid:
return ErrorSemanticAnalyzeFail;
Expand Down
6 changes: 6 additions & 0 deletions src/ir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22095,6 +22095,12 @@ static IrInstruction *ir_analyze_instruction_frame_type(IrAnalyze *ira, IrInstru
if (fn == nullptr)
return ira->codegen->invalid_instruction;

if (fn->type_entry->data.fn.is_generic) {
ir_add_error(ira, &instruction->base,
buf_sprintf("@Frame() of generic function"));
return ira->codegen->invalid_instruction;
}

ZigType *ty = get_fn_frame_type(ira->codegen, fn);
return ir_const_type(ira, &instruction->base, ty);
}
Expand Down
13 changes: 13 additions & 0 deletions test/compile_errors.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@ const tests = @import("tests.zig");
const builtin = @import("builtin");

pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add(
"@Frame() of generic function",
\\export fn entry() void {
\\ var frame: @Frame(func) = undefined;
\\}
\\fn func(comptime T: type) void {
\\ var x: T = undefined;
\\}
,
"tmp.zig:2:16: error: @Frame() of generic function",
);

cases.add(
"@frame() causes function to be async",
\\export fn entry() void {
Expand All @@ -14,6 +26,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
"tmp.zig:1:1: error: function with calling convention 'ccc' cannot be async",
"tmp.zig:5:9: note: @frame() causes function to be async",
);

cases.add(
"invalid suspend in exported function",
\\export fn entry() void {
Expand Down

0 comments on commit 1254a45

Please sign in to comment.