We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent cf2ccbc commit c01186cCopy full SHA for c01186c
vlib/v/gen/c/cgen.v
@@ -4406,6 +4406,8 @@ fn (mut g Gen) enum_decl(node ast.EnumDecl) {
4406
const_def := g.global_const_defs[util.no_dots(field.expr.name)]
4407
if const_def.def.starts_with('#define') {
4408
g.enum_typedefs.write_string(const_def.def.all_after_last(' '))
4409
+ } else if const_def.def.contains('const') {
4410
+ g.enum_typedefs.write_string(const_def.def.all_after_last('=').all_before_last(';'))
4411
} else {
4412
g.enum_typedefs.write_string(expr_str)
4413
}
vlib/v/tests/enums/enum_with_comptime_const_test.v
@@ -0,0 +1,10 @@
1
+const enum_value = $if linux { 1 } $else { 2 }
2
+
3
+pub enum Test {
4
+ a = enum_value
5
+}
6
7
+fn test_enum_with_comptime_const() {
8
+ println(Test.a)
9
+ assert true
10
0 commit comments