Skip to content

Commit 37a7962

Browse files
authored
cgen: fix println(value.name) inside $for value in Test.values{ (#17746)
1 parent 8693da4 commit 37a7962

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

vlib/v/gen/c/cgen.v

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3427,13 +3427,6 @@ fn (mut g Gen) selector_expr(node ast.SelectorExpr) {
34273427
g.error('unknown generic field', node.pos)
34283428
}
34293429
}
3430-
} else {
3431-
// for comp-time enum value evaluation
3432-
if node.expr_type == g.enum_data_type && node.expr is ast.Ident
3433-
&& (node.expr as ast.Ident).name == 'value' {
3434-
g.write(node.str())
3435-
return
3436-
}
34373430
}
34383431
if node.expr_type == 0 {
34393432
g.checker_bug('unexpected SelectorExpr.expr_type = 0', node.pos)

vlib/v/tests/comptime_enum_test.v

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,26 @@ enum Test {
33
bar
44
}
55

6-
fn test_main() {
6+
fn test_print_value_name() {
7+
$for value in Test.values {
8+
println(value.name)
9+
}
10+
}
11+
12+
fn test_print_value_value() {
13+
$for value in Test.values {
14+
println(value.value)
15+
}
16+
}
17+
18+
fn test_print_both() {
19+
$for values in Test.values {
20+
println(values.name)
21+
println(values.value)
22+
}
23+
}
24+
25+
fn test_comptime_for_in_enum_values() {
726
$for item in Test.values {
827
assert item.name in ['foo', 'bar']
928
match item.value {

0 commit comments

Comments
 (0)