cgen: fix enum switch bug in translated code

Alexander Medvednikov 2022-04-22 02:31:16 +03:00 committed by Jef Roosens
parent 08f45023e8
commit 2c59d47fc1
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
1 changed files with 5 additions and 3 deletions

View File

@ -5185,11 +5185,13 @@ fn (mut g Gen) enum_val(node ast.EnumVal) {
// g.write('${it.mod}${it.enum_name}_$it.val')
// g.enum_expr(node)
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
// 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) {