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

checker: fix wrong error message about missing shared on parameter signature (fix #18087) (#18091)

This commit is contained in:
Felipe Pena 2023-05-02 09:52:40 -03:00 committed by GitHub
parent f25ad18851
commit 638f0f69ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 46 additions and 3 deletions

View File

@ -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 {

View 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 {

View 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)
}
}