mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
parent
b59e6b1d06
commit
9839ab6a6c
@ -800,7 +800,7 @@ fn (mut p Parser) fn_args() ([]ast.Param, bool, bool) {
|
||||
|
||||
types_only := p.tok.kind in [.amp, .ellipsis, .key_fn, .lsbr]
|
||||
|| (p.peek_tok.kind == .comma && (p.table.known_type(argname) || is_generic_type))
|
||||
|| p.peek_tok.kind == .dot || p.peek_tok.kind == .rpar
|
||||
|| p.peek_tok.kind == .dot || p.peek_tok.kind == .rpar || p.fn_language == .c
|
||||
|| (p.tok.kind == .key_mut && (p.peek_token(2).kind == .comma
|
||||
|| p.peek_token(2).kind == .rpar || (p.peek_tok.kind == .name
|
||||
&& p.peek_token(2).kind == .dot)))
|
||||
@ -815,9 +815,15 @@ fn (mut p Parser) fn_args() ([]ast.Param, bool, bool) {
|
||||
is_shared := p.tok.kind == .key_shared
|
||||
is_atomic := p.tok.kind == .key_atomic
|
||||
is_mut := p.tok.kind == .key_mut || is_shared || is_atomic
|
||||
mut name := ''
|
||||
if is_mut {
|
||||
p.next()
|
||||
}
|
||||
if p.fn_language == .c && p.tok.kind == .name
|
||||
&& p.peek_tok.kind !in [.comma, .rpar, .dot] {
|
||||
name = p.tok.lit
|
||||
p.next()
|
||||
}
|
||||
if p.tok.kind == .ellipsis {
|
||||
p.next()
|
||||
is_variadic = true
|
||||
@ -875,7 +881,7 @@ fn (mut p Parser) fn_args() ([]ast.Param, bool, bool) {
|
||||
}
|
||||
args << ast.Param{
|
||||
pos: pos
|
||||
name: ''
|
||||
name: name
|
||||
is_mut: is_mut
|
||||
typ: arg_type
|
||||
type_pos: pos
|
||||
|
12
vlib/v/tests/c_function_mut_param/optional_args_test.v
Normal file
12
vlib/v/tests/c_function_mut_param/optional_args_test.v
Normal file
@ -0,0 +1,12 @@
|
||||
module main
|
||||
|
||||
#include "@VMODROOT/code.c"
|
||||
|
||||
fn C.mut_arg(&u8, mut val usize)
|
||||
|
||||
fn test_c_function_mut_param() {
|
||||
key := &u8(1)
|
||||
mut val := usize(1)
|
||||
C.mut_arg(key, mut &val)
|
||||
assert val == usize(5)
|
||||
}
|
Loading…
Reference in New Issue
Block a user