cgen: fix enum print (#11218)

pull/11234/head
div72 2021-08-18 17:11:12 +03:00 committed by GitHub
parent 2bf1015ae1
commit 881510e7ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 7 deletions

View File

@ -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("<none>")')
} 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)

View File

@ -4,3 +4,5 @@ green
green
interp: green
interp: green
orange
orange

View File

@ -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])
}