mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
This commit is contained in:
parent
f25ad18851
commit
638f0f69ed
@ -1086,7 +1086,7 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast.
|
||||
}
|
||||
} else {
|
||||
if param.is_mut {
|
||||
tok := call_arg.share.str()
|
||||
tok := if param.typ.has_flag(.shared_f) { 'shared' } else { call_arg.share.str() }
|
||||
c.error('function `${node.name}` parameter `${param.name}` is `${tok}`, so use `${tok} ${call_arg.expr}` instead',
|
||||
call_arg.expr.pos())
|
||||
} else {
|
||||
@ -1805,7 +1805,7 @@ fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
|
||||
}
|
||||
} else {
|
||||
if param_is_mut {
|
||||
tok := arg.share.str()
|
||||
tok := if param.typ.has_flag(.shared_f) { 'shared' } else { arg.share.str() }
|
||||
c.error('method `${node.name}` parameter `${param.name}` is `${tok}`, so use `${tok} ${arg.expr}` instead',
|
||||
arg.expr.pos())
|
||||
} else {
|
||||
@ -2056,7 +2056,7 @@ fn (mut c Checker) method_call(mut node ast.CallExpr) ast.Type {
|
||||
}
|
||||
} else {
|
||||
if param.is_mut {
|
||||
tok := arg.share.str()
|
||||
tok := if param.typ.has_flag(.shared_f) { 'shared' } else { arg.share.str() }
|
||||
c.error('method `${node.name}` parameter ${i + 1} is `${tok}`, so use `${tok} ${arg.expr}` instead',
|
||||
arg.expr.pos())
|
||||
} else {
|
||||
|
14
vlib/v/checker/tests/shared_param_err.out
Normal file
14
vlib/v/checker/tests/shared_param_err.out
Normal file
@ -0,0 +1,14 @@
|
||||
vlib/v/checker/tests/shared_param_err.vv:23:12: error: method `g` parameter `c` is `shared`, so use `shared a` instead
|
||||
21 | x: 10
|
||||
22 | }
|
||||
23 | spawn a.g(a)
|
||||
| ^
|
||||
24 | spawn foo(a)
|
||||
25 |
|
||||
vlib/v/checker/tests/shared_param_err.vv:24:12: error: function `foo` parameter `b` is `shared`, so use `shared a` instead
|
||||
22 | }
|
||||
23 | spawn a.g(a)
|
||||
24 | spawn foo(a)
|
||||
| ^
|
||||
25 |
|
||||
26 | rlock a {
|
29
vlib/v/checker/tests/shared_param_err.vv
Normal file
29
vlib/v/checker/tests/shared_param_err.vv
Normal file
@ -0,0 +1,29 @@
|
||||
struct St {
|
||||
mut:
|
||||
x int
|
||||
// data to be shared
|
||||
}
|
||||
|
||||
fn (shared b St) g(shared c St) {
|
||||
lock b {
|
||||
b.x = 100
|
||||
}
|
||||
}
|
||||
|
||||
fn foo(shared b St) {
|
||||
lock b {
|
||||
b.x = 101
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
shared a := St{
|
||||
x: 10
|
||||
}
|
||||
spawn a.g(a)
|
||||
spawn foo(a)
|
||||
|
||||
rlock a {
|
||||
println(a.x)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user