-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Comptime falsy accepted #5458
Copy link
Copy link
Open
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior
Milestone
Description
The following code compiles, but shouldn't:
const std = @import("std");
fn foo() type {
return struct {
var N: usize = 0;
fn init() @This() {
comptime {
N += 1;
}
return .{};
}
fn num(this: *const @This()) usize {
comptime {
N += 1;
}
return N;
}
};
}
pub fn main() anyerror!void {
var one = foo().init();
var two = foo().init();
std.debug.print("{} {} {} {}\n", .{ one.num(), two.num(), one.num(), two.num() });
}Notice how it has two comptime { N += 1; } blocks, while in reality it's a runtime add I believe, https://godbolt.org/z/JKrscX
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior