AstGen: add error for redundant comptime var in comptime scope (#18242)
This commit is contained in:
parent
157cdaee0e
commit
4a1a5ee47b
|
@ -200,7 +200,7 @@ const number_test_stems = .{
|
|||
.{ "", "e0", "E0", "e+0", "e-0", "e9999999999999999999999999999" },
|
||||
};
|
||||
const number_test_items = blk: {
|
||||
comptime var ret: []const []const u8 = &[_][]const u8{};
|
||||
var ret: []const []const u8 = &[_][]const u8{};
|
||||
for (number_test_stems[0]) |s0| {
|
||||
for (number_test_stems[1]) |s1| {
|
||||
for (number_test_stems[2]) |s2| {
|
||||
|
|
|
@ -20,7 +20,7 @@ pub fn TrailerFlags(comptime Fields: type) type {
|
|||
|
||||
pub const ActiveFields = std.enums.EnumFieldStruct(FieldEnum, bool, false);
|
||||
pub const FieldValues = blk: {
|
||||
comptime var fields: [bit_count]Type.StructField = undefined;
|
||||
var fields: [bit_count]Type.StructField = undefined;
|
||||
for (@typeInfo(Fields).Struct.fields, 0..) |struct_field, i| {
|
||||
fields[i] = Type.StructField{
|
||||
.name = struct_field.name,
|
||||
|
|
|
@ -3235,6 +3235,8 @@ fn varDecl(
|
|||
return &sub_scope.base;
|
||||
},
|
||||
.keyword_var => {
|
||||
if (var_decl.comptime_token != null and gz.is_comptime)
|
||||
return astgen.failTok(var_decl.comptime_token.?, "'comptime var' is redundant in comptime scope", .{});
|
||||
const is_comptime = var_decl.comptime_token != null or gz.is_comptime;
|
||||
var resolve_inferred_alloc: Zir.Inst.Ref = .none;
|
||||
const alloc: Zir.Inst.Ref, const result_info: ResultInfo = if (var_decl.ast.type_node != 0) a: {
|
||||
|
|
7
test/cases/compile_errors/redundant_comptime_var.zig
Normal file
7
test/cases/compile_errors/redundant_comptime_var.zig
Normal file
|
@ -0,0 +1,7 @@
|
|||
comptime {
|
||||
comptime var x = undefined;
|
||||
}
|
||||
|
||||
// error
|
||||
//
|
||||
// :2:5: error: 'comptime var' is redundant in comptime scope
|
Loading…
Reference in New Issue
Block a user