AstGen: add error for redundant comptime var in comptime scope (#18242)

This commit is contained in:
Bogdan Romanyuk 2024-01-10 04:09:39 +03:00 committed by GitHub
parent 157cdaee0e
commit 4a1a5ee47b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 11 additions and 2 deletions

View File

@ -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| {

View File

@ -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,

View File

@ -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: {

View File

@ -0,0 +1,7 @@
comptime {
comptime var x = undefined;
}
// error
//
// :2:5: error: 'comptime var' is redundant in comptime scope