From 52f473d1c7e22d4897efa26176eacd2f8ecc7043 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Tue, 6 Aug 2019 18:13:04 +0200 Subject: [PATCH] all: fix immutable fn args --- compiler/fn.v | 5 +++-- vlib/builtin/string.v | 10 +++++----- vlib/math/math.v | 4 +++- vlib/os/os.v | 24 ++++++++++++------------ vlib/strings/builder.v | 2 +- 5 files changed, 24 insertions(+), 21 deletions(-) diff --git a/compiler/fn.v b/compiler/fn.v index c65043473f..666416be9f 100644 --- a/compiler/fn.v +++ b/compiler/fn.v @@ -666,6 +666,7 @@ fn (p mut Parser) fn_args(f mut Fn) { } f.args << int_arg } + // `(int, string, int)` // Just register fn arg types types_only := p.tok == .mul || (p.peek() == .comma && p.table.known_type(p.lit)) || p.peek() == .rpar// (int, string) if types_only { @@ -684,12 +685,12 @@ fn (p mut Parser) fn_args(f mut Fn) { } } } - // (a int, b,c string) syntax + // `(a int, b, c string)` syntax for p.tok != .rpar { mut names := [ p.check_name() ] - // a,b,c int syntax + // `a,b,c int` syntax for p.tok == .comma { p.check(.comma) p.fspace() diff --git a/vlib/builtin/string.v b/vlib/builtin/string.v index a676710124..0141e6274e 100644 --- a/vlib/builtin/string.v +++ b/vlib/builtin/string.v @@ -694,13 +694,13 @@ pub fn (s string) ustring_tmp() ustring { return res } -pub fn (u ustring) substr(start, end int) string { - start = u.runes[start] - if end >= u.runes.len { - end = u.s.len +pub fn (u ustring) substr(_start, _end int) string { + start := u.runes[_start] + end := if _end >= u.runes.len { + u.s.len } else { - end = u.runes[end] + u.runes[_end] } return u.s.substr(start, end) } diff --git a/vlib/math/math.v b/vlib/math/math.v index e5639a3d33..3ffce42e6d 100644 --- a/vlib/math/math.v +++ b/vlib/math/math.v @@ -102,7 +102,8 @@ pub fn exp(a f64) f64 { } // digits returns an array of the digits of n in the given base. -pub fn digits(n, base int) []int { +pub fn digits(_n, base int) []int { + mut n := _n mut sign := 1 if n < 0 { sign = -1 @@ -132,6 +133,7 @@ pub fn exp2(a f64) f64 { } // factorial calculates the factorial of the provided value. +// TODO bring back once multiple value functions are implemented fn recursive_product( n int, current_number_ptr &int) int{ mut m := n / 2 if (m == 0){ diff --git a/vlib/os/os.v b/vlib/os/os.v index 8b457e941c..ff3d56d21f 100644 --- a/vlib/os/os.v +++ b/vlib/os/os.v @@ -337,8 +337,8 @@ fn popen(path string) *FILE { } // exec starts the specified command, waits for it to complete, and returns its output. -pub fn exec(cmd string) string { - cmd = '$cmd 2>&1' +pub fn exec(_cmd string) string { + cmd := '$_cmd 2>&1' f := popen(cmd) if isnil(f) { // TODO optional or error code @@ -397,19 +397,19 @@ pub fn unsetenv(name string) int { } // `file_exists` returns true if `path` exists. -pub fn file_exists(path string) bool { +pub fn file_exists(_path string) bool { $if windows { - path = path.replace('/', '\\') - return C._waccess( path.to_wide(), 0 ) != -1 + path := _path.replace('/', '\\') + return C._waccess(path.to_wide(), 0) != -1 } $else { - return C.access( path.str, 0 ) != -1 + return C.access(_path.str, 0 ) != -1 } } pub fn dir_exists(path string) bool { $if windows { - path = path.replace('/', '\\') - attr := int(C.GetFileAttributes(path.to_wide())) + _path := path.replace('/', '\\') + attr := int(C.GetFileAttributes(_path.to_wide())) if attr == INVALID_FILE_ATTRIBUTES { return false } @@ -431,13 +431,13 @@ pub fn dir_exists(path string) bool { // mkdir creates a new directory with the specified path. pub fn mkdir(path string) { $if windows { - path = path.replace('/', '\\') + _path := path.replace('/', '\\') // Windows doesnt recursively create the folders // so we need to help it out here - if path.last_index('\\') != -1 { - mkdir(path.all_before_last('\\')) + if _path.last_index('\\') != -1 { + mkdir(_path.all_before_last('\\')) } - C.CreateDirectory(path.to_wide(), 0) + C.CreateDirectory(_path.to_wide(), 0) } $else { C.mkdir(path.str, 511)// S_IRWXU | S_IRWXG | S_IRWXO diff --git a/vlib/strings/builder.v b/vlib/strings/builder.v index 2285517242..120c00e6a9 100644 --- a/vlib/strings/builder.v +++ b/vlib/strings/builder.v @@ -34,7 +34,7 @@ pub fn (b Builder) str() string { return string(b.buf, b.len) } -pub fn (b Builder) cut(n int) { +pub fn (b mut Builder) cut(n int) { b.len -= n }