Skip to content

Commit f8b74d7

Browse files
authored
checker: allow assign to a shared int var (fix #25986) (#25988)
1 parent eeeb22e commit f8b74d7

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

vlib/v/checker/assign.v

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,8 @@ or use an explicit `unsafe{ a[..] }`, if you do not want a copy of the slice.',
649649
}
650650
}
651651
right_is_ptr := right_type.is_any_kind_of_pointer()
652-
if !right_is_ptr && node.op == .assign && right_type_unwrapped.is_number() {
652+
if !left_type.has_flag(.shared_f) && !right_is_ptr && node.op == .assign
653+
&& right_type_unwrapped.is_number() {
653654
c.error('cannot assign to `${left}`: ' +
654655
c.expected_msg(right_type_unwrapped, left_type_unwrapped), right.pos())
655656
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module main
2+
3+
struct Foo {
4+
mut:
5+
a shared int
6+
}
7+
8+
fn test_main() {
9+
mut x := Foo{}
10+
lock x.a {
11+
x.a = 100
12+
}
13+
rlock x.a {
14+
k := x.a
15+
// can't use assert x.a == 100, to be fixed
16+
assert k == 100
17+
}
18+
}

0 commit comments

Comments
 (0)