diff --git a/vlib/v/gen/c/auto_str_methods.v b/vlib/v/gen/c/auto_str_methods.v index 88ffbf0b00..dbe6630d42 100644 --- a/vlib/v/gen/c/auto_str_methods.v +++ b/vlib/v/gen/c/auto_str_methods.v @@ -326,7 +326,7 @@ fn (mut g Gen) gen_str_for_enum(info ast.Enum, styp string, str_fn_name string) } else if info.is_multi_allowed { seen << val } - g.auto_str_funcs.writeln('\t\tcase ${s}_$val: return _SLIT("$val");') + g.auto_str_funcs.writeln('\t\tcase ${s}__$val: return _SLIT("$val");') } g.auto_str_funcs.writeln('\t\tdefault: return _SLIT("unknown enum value");') g.auto_str_funcs.writeln('\t}') diff --git a/vlib/v/gen/c/cgen.v b/vlib/v/gen/c/cgen.v index 14acacf305..7148ee760a 100644 --- a/vlib/v/gen/c/cgen.v +++ b/vlib/v/gen/c/cgen.v @@ -1201,7 +1201,7 @@ fn (mut g Gen) stmt(node ast.Stmt) { mut cur_enum_expr := '' mut cur_enum_offset := 0 for i, field in node.fields { - g.enum_typedefs.write_string('\t${enum_name}_$field.name') + g.enum_typedefs.write_string('\t${enum_name}__$field.name') if field.has_expr { g.enum_typedefs.write_string(' = ') expr_str := g.expr_string(field.expr) @@ -3176,7 +3176,7 @@ fn (mut g Gen) expr(node ast.Expr) { // g.write('${it.mod}${it.enum_name}_$it.val') // g.enum_expr(node) styp := g.typ(node.typ) - g.write('${styp}_$node.val') + g.write('${styp}__$node.val') } ast.FloatLiteral { g.write(node.val) @@ -4071,9 +4071,9 @@ fn (mut g Gen) select_expr(node ast.SelectExpr) { g.write(', ') } if is_push[i] { - g.write('sync__Direction_push') + g.write('sync__Direction__push') } else { - g.write('sync__Direction_pop') + g.write('sync__Direction__pop') } } g.writeln('}));\n') diff --git a/vlib/v/gen/c/comptime.v b/vlib/v/gen/c/comptime.v index e6c29a1889..40f0994d87 100644 --- a/vlib/v/gen/c/comptime.v +++ b/vlib/v/gen/c/comptime.v @@ -519,7 +519,7 @@ fn (mut g Gen) comp_for(node ast.CompFor) { g.writeln('\t${node.val_var}.name = _SLIT("$attr.name");') g.writeln('\t${node.val_var}.has_arg = $attr.has_arg;') g.writeln('\t${node.val_var}.arg = _SLIT("$attr.arg");') - g.writeln('\t${node.val_var}.kind = AttributeKind_$attr.kind;') + g.writeln('\t${node.val_var}.kind = AttributeKind__$attr.kind;') g.writeln('}') } diff --git a/vlib/v/tests/enum_test.v b/vlib/v/tests/enum_test.v index 1c5bf874b9..e9ef0f0ba5 100644 --- a/vlib/v/tests/enum_test.v +++ b/vlib/v/tests/enum_test.v @@ -133,3 +133,14 @@ fn test_enum_instance() { s := 'x $filetype z' assert s == 'x unknown z' } + +enum Bar { + baz +} + +fn (_ Bar) baz() {} + +fn test_enum_variant_and_method_name_clash() { + x := Bar.baz + println(x) +}