add compile error for async frames depending on themselves

This commit is contained in:
Andrew Kelley
2019-08-17 19:47:49 -04:00
parent 57b90d2d98
commit ea1734773b
3 changed files with 85 additions and 2 deletions

View File

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