mirror of
https://github.com/ziglang/zig.git
synced 2025-12-30 10:03:21 +00:00
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
38 lines
1.3 KiB
Zig
38 lines
1.3 KiB
Zig
const std = @import("std");
|
|
|
|
// big enums should not hit the eval branch quota
|
|
pub fn main() void {
|
|
const big = struct {
|
|
const Big = @Type(.{ .@"enum" = .{
|
|
.tag_type = u16,
|
|
.fields = make_fields: {
|
|
var fields: [1001]std.builtin.Type.EnumField = undefined;
|
|
for (&fields, 0..) |*field, i| {
|
|
field.* = .{ .name = std.fmt.comptimePrint("field_{d}", .{i}), .value = i };
|
|
}
|
|
fields[1000] = .{ .name = "field_9999", .value = 9999 };
|
|
break :make_fields &fields;
|
|
},
|
|
.decls = &.{},
|
|
.is_exhaustive = true,
|
|
} });
|
|
};
|
|
|
|
var set = std.enums.EnumSet(big.Big).init(.{});
|
|
_ = &set;
|
|
|
|
var map = std.enums.EnumMap(big.Big, u8).init(undefined);
|
|
map = std.enums.EnumMap(big.Big, u8).initFullWith(undefined);
|
|
map = std.enums.EnumMap(big.Big, u8).initFullWithDefault(123, .{});
|
|
|
|
var multiset = std.enums.EnumMultiset(big.Big).init(.{});
|
|
_ = &multiset;
|
|
|
|
var bounded_multiset = std.enums.BoundedEnumMultiset(big.Big, u8).init(.{});
|
|
_ = &bounded_multiset;
|
|
|
|
@setEvalBranchQuota(3000);
|
|
var array = std.enums.EnumArray(big.Big, u8).init(undefined);
|
|
array = std.enums.EnumArray(big.Big, u8).initDefault(123, .{});
|
|
}
|