1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

make function arguments immutable by default

This commit is contained in:
Alexander Medvednikov
2019-08-07 08:19:27 +02:00
parent 06b8bd9382
commit 34e0b164eb
22 changed files with 107 additions and 83 deletions

View File

@ -242,7 +242,8 @@ fn (t mut Table) register_fn(new_fn Fn) {
t.fns[new_fn.name] = new_fn
}
fn (table &Table) known_type(typ string) bool {
fn (table &Table) known_type(typ_ string) bool {
mut typ := typ_
// 'byte*' => look up 'byte', but don't mess up fns
if typ.ends_with('*') && !typ.contains(' ') {
typ = typ.left(typ.len - 1)
@ -441,7 +442,8 @@ fn (p &Parser) find_type(name string) *Type {
return typ
}
fn (t &Table) find_type(name string) *Type {
fn (t &Table) find_type(name_ string) *Type {
mut name := name_
if name.ends_with('*') && !name.contains(' ') {
name = name.left(name.len - 1)
}
@ -454,7 +456,9 @@ fn (t &Table) find_type(name string) *Type {
return &Type{}
}
fn (p mut Parser) _check_types(got, expected string, throw bool) bool {
fn (p mut Parser) _check_types(got_, expected_ string, throw bool) bool {
mut got := got_
mut expected := expected_
p.log('check types got="$got" exp="$expected" ')
if p.pref.translated {
return true
@ -582,8 +586,7 @@ fn (p mut Parser) satisfies_interface(interface_name, _typ string, throw bool) b
fn type_default(typ string) string {
if typ.starts_with('array_') {
typ = typ.right(6)
return 'new_array(0, 1, sizeof($typ))'
return 'new_array(0, 1, sizeof( ${typ.right(6)} ))'
}
// Always set pointers to 0
if typ.ends_with('*') {
@ -776,8 +779,8 @@ fn (p mut Parser) typ_to_fmt(typ string, level int) string {
return ''
}
fn is_compile_time_const(s string) bool {
s = s.trim_space()
fn is_compile_time_const(s_ string) bool {
s := s_.trim_space()
if s == '' {
return false
}