cgen: prepend __ to new_array

pull/4427/head
Kris Cherven 2020-04-15 14:12:06 -04:00 committed by GitHub
parent 27b6f30305
commit a3ab5df2ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

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

View File

@ -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), ')