mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
json.decode: add check for shared variable (#18237)
This commit is contained in:
parent
6698fe4f60
commit
598673314b
@ -635,6 +635,9 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast.
|
||||
}
|
||||
}
|
||||
panic('unreachable')
|
||||
} else if node.args.len > 0 && fn_name == 'json.encode' && node.args[0].typ.has_flag(.shared_f) {
|
||||
c.error('json.encode cannot handle shared data', node.pos)
|
||||
return ast.void_type
|
||||
} else if node.args.len > 0 && fn_name == 'json.decode' {
|
||||
if node.args.len != 2 {
|
||||
c.error("json.decode expects 2 arguments, a type and a string (e.g `json.decode(T, '')`)",
|
||||
|
7
vlib/v/checker/tests/json_decode_shared_err.out
Normal file
7
vlib/v/checker/tests/json_decode_shared_err.out
Normal file
@ -0,0 +1,7 @@
|
||||
vlib/v/checker/tests/json_decode_shared_err.vv:6:16: error: json.encode cannot handle shared data
|
||||
4 | shared data := [1, 2, 3]
|
||||
5 | rlock data {
|
||||
6 | println(json.encode(data))
|
||||
| ~~~~~~~~~~~~
|
||||
7 | }
|
||||
8 | }
|
8
vlib/v/checker/tests/json_decode_shared_err.vv
Normal file
8
vlib/v/checker/tests/json_decode_shared_err.vv
Normal file
@ -0,0 +1,8 @@
|
||||
import json
|
||||
|
||||
fn main() {
|
||||
shared data := [1, 2, 3]
|
||||
rlock data {
|
||||
println(json.encode(data))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user