From 881510e7ce9133631190a353eda6c79d5f426f0c Mon Sep 17 00:00:00 2001 From: div72 <60045611+div72@users.noreply.github.com> Date: Wed, 18 Aug 2021 17:11:12 +0300 Subject: [PATCH] cgen: fix enum print (#11218) --- vlib/v/gen/c/str.v | 6 +----- vlib/v/tests/inout/enum_print.out | 4 +++- vlib/v/tests/inout/enum_print.vv | 4 +++- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/vlib/v/gen/c/str.v b/vlib/v/gen/c/str.v index a4b9ae43c2..788da2c23d 100644 --- a/vlib/v/gen/c/str.v +++ b/vlib/v/gen/c/str.v @@ -92,11 +92,7 @@ fn (mut g Gen) gen_expr_to_string(expr ast.Expr, etype ast.Type) { } else if sym.kind == .none_ { g.write('_SLIT("")') } else if sym.kind == .enum_ { - is_var := match expr { - ast.SelectorExpr, ast.Ident, ast.CTempVar { true } - else { false } - } - if is_var { + if expr !is ast.EnumVal { str_fn_name := g.gen_str_for_type(typ) g.write('${str_fn_name}(') g.enum_expr(expr) diff --git a/vlib/v/tests/inout/enum_print.out b/vlib/v/tests/inout/enum_print.out index 362ee21355..641cb0b607 100644 --- a/vlib/v/tests/inout/enum_print.out +++ b/vlib/v/tests/inout/enum_print.out @@ -3,4 +3,6 @@ yellow green green interp: green -interp: green \ No newline at end of file +interp: green +orange +orange \ No newline at end of file diff --git a/vlib/v/tests/inout/enum_print.vv b/vlib/v/tests/inout/enum_print.vv index 473a645a04..3602ca09dc 100644 --- a/vlib/v/tests/inout/enum_print.vv +++ b/vlib/v/tests/inout/enum_print.vv @@ -7,7 +7,7 @@ enum Color { yellow = 3 } -struct Aaa{ +struct Aaa { color Color } @@ -21,4 +21,6 @@ fn main() { println(a.color) println('interp: ${col}') println('interp: ${a.color}') + println((Color.orange)) + println([Color.orange, Color.green][0]) }