From 1254a453b91623849dcb0a655b1212c9a179d29a Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Fri, 16 Aug 2019 10:44:42 -0400 Subject: [PATCH] add compile error for @Frame() of generic function See #3063 --- src/analyze.cpp | 2 ++ src/ir.cpp | 6 ++++++ test/compile_errors.zig | 13 +++++++++++++ 3 files changed, 21 insertions(+) diff --git a/src/analyze.cpp b/src/analyze.cpp index 21289f24a8f01a3df08b3d4ee47f3da856927127..4aff6da8e905f910e4e1092eabc5d4bd380bd1f7 100644 --- a/src/analyze.cpp +++ b/src/analyze.cpp @@ -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; diff --git a/src/ir.cpp b/src/ir.cpp index ddaf82893a96c7b20fc8a5c301150cb900f08129..9589000ab06dc4e2fd847ca8a279713c8ff2f2e7 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -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); } diff --git a/test/compile_errors.zig b/test/compile_errors.zig index 0d579ece95d0fc6c47e29ca889beca61a2f01c4e..c4549be4057981f719feb0b0feff069bf79033a6 100644 --- a/test/compile_errors.zig +++ b/test/compile_errors.zig @@ -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 { -- 2.54.0