add compile error for async frames depending on themselves
This commit is contained in:
@@ -2,6 +2,42 @@ const tests = @import("tests.zig");
|
||||
const builtin = @import("builtin");
|
||||
|
||||
pub fn addCases(cases: *tests.CompileErrorContext) void {
|
||||
cases.add(
|
||||
"indirect recursion of async functions detected",
|
||||
\\var frame: ?anyframe = null;
|
||||
\\
|
||||
\\export fn a() void {
|
||||
\\ _ = async rangeSum(10);
|
||||
\\ while (frame) |f| resume f;
|
||||
\\}
|
||||
\\
|
||||
\\fn rangeSum(x: i32) i32 {
|
||||
\\ suspend {
|
||||
\\ frame = @frame();
|
||||
\\ }
|
||||
\\ frame = null;
|
||||
\\
|
||||
\\ if (x == 0) return 0;
|
||||
\\ var child = rangeSumIndirect(x - 1);
|
||||
\\ return child + 1;
|
||||
\\}
|
||||
\\
|
||||
\\fn rangeSumIndirect(x: i32) i32 {
|
||||
\\ suspend {
|
||||
\\ frame = @frame();
|
||||
\\ }
|
||||
\\ frame = null;
|
||||
\\
|
||||
\\ if (x == 0) return 0;
|
||||
\\ var child = rangeSum(x - 1);
|
||||
\\ return child + 1;
|
||||
\\}
|
||||
,
|
||||
"tmp.zig:8:1: error: '@Frame(rangeSum)' depends on itself",
|
||||
"tmp.zig:15:33: note: when analyzing type '@Frame(rangeSumIndirect)' here",
|
||||
"tmp.zig:26:25: note: when analyzing type '@Frame(rangeSum)' here",
|
||||
);
|
||||
|
||||
cases.add(
|
||||
"non-async function pointer eventually is inferred to become async",
|
||||
\\export fn a() void {
|
||||
|
||||
Reference in New Issue
Block a user