Fix if expressions in lock expression#14384
Conversation
| @@ -1,5 +1,5 @@ | |||
| fn test_shared_modification() { | |||
| shared foo := &[2, 0, 5] | |||
| shared foo := [2, 0, 5] | |||
There was a problem hiding this comment.
the removals of & seem to be unrelated to the PR?
There was a problem hiding this comment.
shared implies a reference and the underlying type looks like this;
struct __shared__Array_int {
sync__RwMutex mtx;
Array_int val;
};and then whenever you creacte a shared foo, you create a reference to __shared__Array_int, not the Array_int:
__shared__Array_int* foo = (__shared__Array_int*)__dup_shared_array(&(__shared__Array_int){.mtx = {0}, .val =
new_array_from_c_array(3, 3, sizeof(int), _MOV((int[3]){2, 0, 5}))}, sizeof(__shared__Array_int));This was generated with current V, and it didn't generate a reference to the array anyways.
This PR makes assignments always use expr_with_cast, which doesn't allow casting a reference to shared:
Line 2212 in cee7856
You need a reference to
__shared__Array_int because the mutexes all need to be the same one in memory, and having a shared reference is usually (always?) never what you want.
There was a problem hiding this comment.
This cgen error is not triggered by any of the existing tests, and the tests that are changed, compile fine on both master and the branch of this PR.
There was a problem hiding this comment.
The file vlib/v/tests/shared_if_expr_test.v is the only test file that should stay in the PR imho.
There was a problem hiding this comment.
@spytheman he's removing unnecessary &[] from the code. It's already handled by V when it sees it's shared.
There was a problem hiding this comment.
I understand that.
But it is handled by V now.
It is not guaranteed to be handled by V in the future.
By not changing these tests, it would be, because they will break and the CI will tell us when that happens.
There was a problem hiding this comment.
btw, I have no objections to making it an explicit checker error, and a corresponding test for it.
This reverts commit 368df24.

No description provided.