From 9e715b870190991ca2921c21db86c966d1c619c4 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 5 May 2020 19:28:25 +0300 Subject: [PATCH] cgen: use c_name() while generating code for `or {}` --- vlib/v/gen/cgen.v | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index df33b8de0b..664f8bb0de 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -2654,18 +2654,19 @@ fn (mut g Gen) insert_before(s string) { // to access its fields (`.ok`, `.error` etc) // `os.cp(...)` => `Option bool tmp = os__cp(...); if (!tmp.ok) { ... }` fn (mut g Gen) or_block(var_name string, stmts []ast.Stmt, return_type table.Type) { + cvar_name := c_name(var_name) mr_styp := g.base_type(return_type) g.writeln(';') // or') - g.writeln('if (!${var_name}.ok) {') - g.writeln('\tstring err = ${var_name}.v_error;') - g.writeln('\tint errcode = ${var_name}.ecode;') + g.writeln('if (!${cvar_name}.ok) {') + g.writeln('\tstring err = ${cvar_name}.v_error;') + g.writeln('\tint errcode = ${cvar_name}.ecode;') last_type, type_of_last_expression := g.type_of_last_statement(stmts) if last_type == 'v.ast.ExprStmt' && type_of_last_expression != 'void' { g.indent++ for i, stmt in stmts { if i == stmts.len - 1 { g.indent-- - g.write('\t*(${mr_styp}*) ${var_name}.data = ') + g.write('\t*(${mr_styp}*) ${cvar_name}.data = ') } g.stmt(stmt) }