zig/test/cases/compile_errors/recursive_inline_fn.zig
mlugg e9bd2d45d4
Sema: rewrite semantic analysis of function calls
This rewrite improves some error messages, hugely simplifies the logic,
and fixes several bugs. One of these bugs is technically a new rule
which Andrew and I agreed on: if a parameter has a comptime-only type
but is not declared `comptime`, then the corresponding call argument
should not be *evaluated* at comptime; only resolved. Implementing this
required changing how function types work a little, which in turn
required allowing a new kind of function coercion for some generic use
cases: function coercions are now allowed to implicitly *remove*
`comptime` annotations from parameters with comptime-only types. This is
okay because removing the annotation affects only the call site.

Resolves: #22262
2025-01-09 06:46:47 +00:00

38 lines
611 B
Zig

inline fn foo(x: i32) i32 {
if (x <= 0) {
return 0;
} else {
return x * 2 + foo(x - 1);
}
}
pub export fn entry() void {
var x: i32 = 4;
_ = &x;
_ = foo(x) == 20;
}
inline fn first() void {
second();
}
inline fn second() void {
third();
}
inline fn third() void {
first();
}
pub export fn entry2() void {
first();
}
// error
//
// :5:27: error: inline call is recursive
// :12:12: note: called from here
// :24:10: error: inline call is recursive
// :20:10: note: called from here
// :16:11: note: called from here
// :28:10: note: called from here