mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
checker: disallow static maps: mut static x := map[string]int{}
(#20596)
This commit is contained in:
parent
9092d7fd64
commit
0d9e5e5747
3 changed files with 25 additions and 0 deletions
|
@ -597,6 +597,13 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.',
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if mut left is ast.Ident {
|
||||||
|
if mut left.info is ast.IdentVar {
|
||||||
|
if left.info.is_static && right_sym.kind == .map {
|
||||||
|
c.error('maps cannot be static', left.pos)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
// Single side check
|
// Single side check
|
||||||
match node.op {
|
match node.op {
|
||||||
.assign {} // No need to do single side check for =. But here put it first for speed.
|
.assign {} // No need to do single side check for =. But here put it first for speed.
|
||||||
|
|
7
vlib/v/checker/tests/static_maps_err.out
Normal file
7
vlib/v/checker/tests/static_maps_err.out
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
vlib/v/checker/tests/static_maps_err.vv:3:13: error: maps cannot be static
|
||||||
|
1 | @[unsafe]
|
||||||
|
2 | fn foo() map[string]int {
|
||||||
|
3 | mut static x := map[string]int{}
|
||||||
|
| ^
|
||||||
|
4 | return x
|
||||||
|
5 | }
|
11
vlib/v/checker/tests/static_maps_err.vv
Normal file
11
vlib/v/checker/tests/static_maps_err.vv
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
@[unsafe]
|
||||||
|
fn foo() map[string]int {
|
||||||
|
mut static x := map[string]int{}
|
||||||
|
return x
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
unsafe {
|
||||||
|
foo()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue