From 99cf520bd4fbabf15ffada675e6535cda0611daa Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Wed, 6 May 2020 12:13:19 +0200 Subject: [PATCH] parser: `mut x Type` syntax for args --- vlib/v/parser/fn.v | 12 ++++++++---- vlib/v/tests/fn_test.v | 8 ++++++++ 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/vlib/v/parser/fn.v b/vlib/v/parser/fn.v index e0bc65c527..5c4dbb35cc 100644 --- a/vlib/v/parser/fn.v +++ b/vlib/v/parser/fn.v @@ -358,16 +358,20 @@ fn (mut p Parser) fn_args() ([]table.Arg, bool) { } } else { for p.tok.kind != .rpar { + mut is_mut := p.tok.kind == .key_mut + if is_mut { + p.next() + } mut arg_names := [p.check_name()] // `a, b, c int` for p.tok.kind == .comma { p.check(.comma) arg_names << p.check_name() } - is_mut := p.tok.kind == .key_mut - // if is_mut { - // p.check(.key_mut) - // } + if p.tok.kind == .key_mut { + // TODO remove old syntax + is_mut = true + } if p.tok.kind == .ellipsis { p.check(.ellipsis) is_variadic = true diff --git a/vlib/v/tests/fn_test.v b/vlib/v/tests/fn_test.v index 902991285e..1ee3ea0b2e 100644 --- a/vlib/v/tests/fn_test.v +++ b/vlib/v/tests/fn_test.v @@ -65,6 +65,14 @@ fn modify_array(a mut []int) { // a << 888 } +fn modify_array2(mut a []int) { + a[0] = 10 + for i in 0 .. a.len { + a[i] = a[i] * 2 + } + // a << 888 +} + fn test_mut_array() { mut nums := [1, 2, 3] modify_array(mut nums)