You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
test"functions in an array" {
constTestFn=fn () void;
consttest_fns= [_]TestFn{ foo, bar };
for (test_fns) |testFn| {
testFn();
}
}
fnfoo() void {}
fnbar() void {}
$ ./stage2/bin/zig test test3.zig
thread 2885489 panic: Segmentation fault at address 0x0
???:?:?: 0x3eb6328 in ??? (???)
Panicked during a panic: integer overflow
Inner panic stack:
/home/andy/Downloads/zig/lib/std/debug.zig:169:69: 0x3314122 in std.debug.dumpStackTraceFromBase (zig)
printSourceAtAddress(debug_info, stderr, return_address - 1, tty_config) catch return;
^
/home/andy/Downloads/zig/src/crash_report.zig:327:45: 0x31af4a2 in crash_report.StackContext.dumpStackTrace (zig)
debug.dumpStackTraceFromBase(ex.bp, ex.ip);
^
/home/andy/Downloads/zig/src/crash_report.zig:479:39: 0x31af050 in crash_report.PanicSwitch.reportStack (zig)
state.panic_ctx.dumpStackTrace();
^
/home/andy/Downloads/zig/src/crash_report.zig:553:9: 0x2fc80e0 in crash_report.PanicSwitch.initPanic (zig)
@call(.{}, func, args);
^
/home/andy/Downloads/zig/src/crash_report.zig:553:9: 0x2cc1845 in crash_report.PanicSwitch.dispatch (zig)
@call(.{}, func, args);
^
/home/andy/Downloads/zig/src/crash_report.zig:254:25: 0x2fc9577 in crash_report.handleSegfaultPosix (zig)
PanicSwitch.dispatch(null, stack_ctx, error_msg);
^
Aborted (core dumped)
This is an important case to get right because it's code that is valid for stage1 which now has different function type semantics in stage2. It should be resolved in one of two ways:
A compile error explaining that testFn is a runtime-known value and so its type must not be a compile-time-only type. A hint should say that inline for would solve this problem. A hint should also say that function bodies are comptime-only while function pointers are OK for runtime, and that & can be used to convert a function body to its pointer.
Or it should implicitly cause the for to become an inline for.
For the former, you can see stage1 already handles a similar case pretty well:
test"functions in an array" {
consttypes= [_]type{ i32, bool };
for (types) |T| {
_=T;
}
}
$ ./stage1/bin/zig test test3.zig
./test3.zig:6:5: error: values of type 'type' must be comptime known, but index value is runtime known
for (types) |T| {
^
The text was updated successfully, but these errors were encountered:
andrewrk
added
bug
Observed behavior contradicts documented or intended behavior
frontend
Tokenization, parsing, AstGen, Sema, and Liveness.
labels
May 11, 2022
Zig Version:
0.10.0-dev.2159+f5edf78ee
This is an important case to get right because it's code that is valid for stage1 which now has different function type semantics in stage2. It should be resolved in one of two ways:
testFn
is a runtime-known value and so its type must not be a compile-time-only type. A hint should say thatinline for
would solve this problem. A hint should also say that function bodies are comptime-only while function pointers are OK for runtime, and that&
can be used to convert a function body to its pointer.for
to become aninline for
.For the former, you can see stage1 already handles a similar case pretty well:
The text was updated successfully, but these errors were encountered: