add compile error for @Frame() of generic function

See #3063
This commit is contained in:
Andrew Kelley 2019-08-16 10:44:42 -04:00
parent 49c88e23af
commit 1254a453b9
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
3 changed files with 21 additions and 0 deletions

View File

@ -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;

View File

@ -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);
}

View File

@ -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 {
@ -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 {