1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

cgen: fix enum switch bug in translated code

This commit is contained in:
Alexander Medvednikov 2022-04-22 02:31:16 +03:00
parent 03d21a727e
commit 9b565bf765

View File

@ -5185,12 +5185,14 @@ fn (mut g Gen) enum_val(node ast.EnumVal) {
// g.write('${it.mod}${it.enum_name}_$it.val') // g.write('${it.mod}${it.enum_name}_$it.val')
// g.enum_expr(node) // g.enum_expr(node)
styp := g.typ(g.table.unaliased_type(node.typ)) styp := g.typ(g.table.unaliased_type(node.typ))
if node.typ.is_number() { // && g.inside_switch
if g.pref.translated && node.typ.is_number() {
// Mostly in translated code, when C enums are used as ints in switches // Mostly in translated code, when C enums are used as ints in switches
// g.write('/*enum val is_number $node.mod styp=$styp*/') g.write('/*enum val is_number $node.mod styp=$styp*/_const_main__$node.val')
} } else {
g.write('${styp}__$node.val') g.write('${styp}__$node.val')
} }
}
fn (mut g Gen) as_cast(node ast.AsCast) { fn (mut g Gen) as_cast(node ast.AsCast) {
// Make sure the sum type can be cast to this type (the types // Make sure the sum type can be cast to this type (the types