Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

checker, cgen: make the shared variable to be whole reassigned(fix #15649) #19751

Merged
merged 1 commit into from Nov 5, 2023

Conversation

shove70
Copy link
Contributor

@shove70 shove70 commented Nov 3, 2023

This PR:

  1. Fixed V panics when using shared variable #15649
  2. make the shared variable to be whole reassigned
fn test(shared values []int) {
	lock values {
		values = [2]
		println(values)
	}
}

fn main() {
	shared values := [3, 3, 3]
	test(shared values)
}

outputs:

[2]

Currently, V only supports the assignment of shared variables at definition time and the assignment of their members and elements, but not whole reassign to it self:

shared arr := [1, 2, 3]
lock arr {
    arr = [2]   // V panic and cgen error.
    arr[0] = 2  // this OK.
}

struct Foo{
    a int
}

shared st := Foo{}
lock st {
    st = Foo{}  // V panic and cgen error.
    st.a = 1    // this OK.
}

// Same goes for map.

@shove70 shove70 marked this pull request as ready for review November 3, 2023 11:35
@shove70 shove70 marked this pull request as draft November 3, 2023 19:32
@shove70 shove70 marked this pull request as ready for review November 4, 2023 08:58
@spytheman spytheman merged commit 510f091 into vlang:master Nov 5, 2023
54 checks passed
@shove70 shove70 deleted the shared_re_assign branch November 5, 2023 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

V panics when using shared variable
2 participants