diff --git a/vlib/v/checker/comptime.v b/vlib/v/checker/comptime.v index aee7aea3ddfff8..894e4f10c6c146 100644 --- a/vlib/v/checker/comptime.v +++ b/vlib/v/checker/comptime.v @@ -294,6 +294,7 @@ fn (mut c Checker) comptime_for(mut node ast.ComptimeFor) { for field in fields { c.push_new_comptime_info() c.comptime.inside_comptime_for = true + c.table.used_features.comptime_for = true if c.field_data_type == 0 { c.field_data_type = c.table.find_type('FieldData') } diff --git a/vlib/v/tests/skip_unused/comptime_for_fields.run.out b/vlib/v/tests/skip_unused/comptime_for_fields.run.out new file mode 100644 index 00000000000000..baed14f1276d6a --- /dev/null +++ b/vlib/v/tests/skip_unused/comptime_for_fields.run.out @@ -0,0 +1 @@ +['alias'] diff --git a/vlib/v/tests/skip_unused/comptime_for_fields.skip_unused.run.out b/vlib/v/tests/skip_unused/comptime_for_fields.skip_unused.run.out new file mode 100644 index 00000000000000..baed14f1276d6a --- /dev/null +++ b/vlib/v/tests/skip_unused/comptime_for_fields.skip_unused.run.out @@ -0,0 +1 @@ +['alias'] diff --git a/vlib/v/tests/skip_unused/comptime_for_fields.vv b/vlib/v/tests/skip_unused/comptime_for_fields.vv new file mode 100644 index 00000000000000..52d728c431f06d --- /dev/null +++ b/vlib/v/tests/skip_unused/comptime_for_fields.vv @@ -0,0 +1,11 @@ +module main + +struct Post { + title string @[alias] +} + +fn main() { + $for field in Post.fields { + println(field.attrs) + } +}