mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: add missing check for global var on assignment to shared var (#18125)
This commit is contained in:
parent
61a5fbea35
commit
d62c4c9fc1
@ -221,6 +221,13 @@ fn (mut c Checker) assign_stmt(mut node ast.AssignStmt) {
|
|||||||
// c.error('cannot assign a `none` value to a non-option variable', right.pos())
|
// c.error('cannot assign a `none` value to a non-option variable', right.pos())
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
if mut left is ast.Ident
|
||||||
|
&& (left as ast.Ident).info is ast.IdentVar && right is ast.Ident && (right as ast.Ident).name in c.global_names {
|
||||||
|
ident_var_info := left.info as ast.IdentVar
|
||||||
|
if ident_var_info.share == .shared_t {
|
||||||
|
c.error('cannot assign global variable to shared variable', right.pos())
|
||||||
|
}
|
||||||
|
}
|
||||||
if right_type.is_ptr() && left_type.is_ptr() {
|
if right_type.is_ptr() && left_type.is_ptr() {
|
||||||
if mut right is ast.Ident {
|
if mut right is ast.Ident {
|
||||||
if mut right.obj is ast.Var {
|
if mut right.obj is ast.Var {
|
||||||
|
12
vlib/v/checker/tests/globals/assign_global_to_shared_err.out
Normal file
12
vlib/v/checker/tests/globals/assign_global_to_shared_err.out
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
vlib/v/checker/tests/globals/assign_global_to_shared_err.vv:5:9: warning: unused variable: `b`
|
||||||
|
3 |
|
||||||
|
4 | fn main() {
|
||||||
|
5 | shared b := a
|
||||||
|
| ^
|
||||||
|
6 | }
|
||||||
|
vlib/v/checker/tests/globals/assign_global_to_shared_err.vv:5:14: error: cannot assign global variable to shared variable
|
||||||
|
3 |
|
||||||
|
4 | fn main() {
|
||||||
|
5 | shared b := a
|
||||||
|
| ^
|
||||||
|
6 | }
|
@ -0,0 +1,6 @@
|
|||||||
|
[has_globals]
|
||||||
|
__global a = 0
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
shared b := a
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user