From a3ab5df2ed690e728582649a260b202fa879d48a Mon Sep 17 00:00:00 2001 From: Kris Cherven <50562493+krischerven@users.noreply.github.com> Date: Wed, 15 Apr 2020 14:12:06 -0400 Subject: [PATCH] cgen: prepend __ to new_array --- vlib/builtin/array.v | 4 ++++ vlib/v/gen/cgen.v | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/vlib/builtin/array.v b/vlib/builtin/array.v index 8b9a1d1ab7..2d45188847 100644 --- a/vlib/builtin/array.v +++ b/vlib/builtin/array.v @@ -28,6 +28,10 @@ fn new_array(mylen int, cap int, elm_size int) array { return arr } +fn __new_array(mylen int, cap int, elm_size int) array { + return new_array(mylen, cap, elm_size) +} + // TODO pub fn make(len int, cap int, elm_size int) array { return new_array(len, cap, elm_size) diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index b2a0abc397..f4de5c57d1 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -865,7 +865,8 @@ fn (g mut Gen) expr(node ast.Expr) { elem_sym := g.table.get_type_symbol(it.elem_type) elem_type_str := g.typ(it.elem_type) if it.exprs.len == 0 { - g.write('new_array($it.exprs.len, $it.exprs.len, sizeof($elem_type_str))') + // use __new_array to fix conflicts when the name of the variable is new_array + g.write('__new_array($it.exprs.len, $it.exprs.len, sizeof($elem_type_str))') } else { len := it.exprs.len g.write('new_array_from_c_array($len, $len, sizeof($elem_type_str), ')