-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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: fix immutable to mutable reference #22663
Merged
Merged
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
72421ae
fix
felipensp e38351e
fix
felipensp 1c10588
fix
felipensp 5e833d2
fix
felipensp 01e97ae
fix
felipensp 74b5a05
fix
felipensp fc5570c
fix
felipensp 6d3e774
fix test
felipensp 962691f
fix
felipensp da059ac
fix
felipensp 22458a8
fix
felipensp 31028e3
fix test
felipensp 94893f1
fix
felipensp 28bf68b
fix test
felipensp 483a1ff
Merge remote-tracking branch 'origin/master' into fix_immutable_to_mu…
felipensp b827bc0
fix
felipensp e459173
Merge remote-tracking branch 'origin/master' into fix_immutable_to_mu…
felipensp 54fc630
fix test
felipensp b75f10a
Merge remote-tracking branch 'origin/master' into fix_immutable_to_mu…
felipensp 727db95
fix
felipensp dbd67af
fix
felipensp 166e172
fix
felipensp b836e73
fix
felipensp 28983ba
fix
felipensp 50479f0
fix
felipensp 4e7e91d
fix
felipensp 13d9ebe
fix test
felipensp e338a48
fix
felipensp fc84a19
fix
felipensp a97c2c2
fix
felipensp 870e465
fix test
felipensp 4e82d70
fix
felipensp 2665743
fix test
felipensp 8f0bead
fix
felipensp 59273c3
fix test
felipensp 8cc0992
fix
felipensp 11177f8
Merge branch 'fix_immutable_to_mutable' of https://github.com/felipen…
felipensp d82c24e
fix
felipensp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
vlib/v/checker/tests/deprecations_consts.vv:3:25: error: const `deprecated_consts.a_deprecated_const` has been deprecated since 2023-12-31; use built-in constant min_i8 instead | ||
1 | import deprecated_consts | ||
2 | fn main() { | ||
3 | dump(deprecated_consts.a_deprecated_const) | ||
vlib/v/checker/tests/deprecations_consts.vv:4:25: error: const `deprecated_consts.a_deprecated_const` has been deprecated since 2023-12-31; use built-in constant min_i8 instead | ||
2 | | ||
3 | fn main() { | ||
4 | dump(deprecated_consts.a_deprecated_const) | ||
| ~~~~~~~~~~~~~~~~~~ | ||
4 | } | ||
5 | } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import deprecated_consts | ||
|
||
fn main() { | ||
dump(deprecated_consts.a_deprecated_const) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
vlib/v/checker/tests/immutable_to_mutable_err.vv:10:27: notice: left-side of assignment expects a mutable reference, but variable `arr` is immutable, declare it with `mut` to make it mutable or clone it | ||
8 | fn main() { | ||
9 | arr := [1, 2, 3] // declared as immutable! | ||
10 | mut arr_mut := if true { arr } else { []int{} } | ||
| ~~~ | ||
11 | mut arr_mut2 := match true { | ||
12 | true { arr } | ||
vlib/v/checker/tests/immutable_to_mutable_err.vv:12:10: notice: left-side of assignment expects a mutable reference, but variable `arr` is immutable, declare it with `mut` to make it mutable or clone it | ||
10 | mut arr_mut := if true { arr } else { []int{} } | ||
11 | mut arr_mut2 := match true { | ||
12 | true { arr } | ||
| ~~~ | ||
13 | else { [0] } | ||
14 | } | ||
vlib/v/checker/tests/immutable_to_mutable_err.vv:22:15: error: use `mut array2 := array1.clone()` instead of `mut array2 := array1` (or use `unsafe`) | ||
20 | | ||
21 | a := Test{} | ||
22 | mut arr_mut3 := a.foo | ||
| ~~ | ||
23 | arr_mut3[0] = 999 | ||
24 | assert a.foo == [1, 2, 3] | ||
vlib/v/checker/tests/immutable_to_mutable_err.vv:26:15: error: use `mut array2 := array1.clone()` instead of `mut array2 := array1` (or use `unsafe`) | ||
24 | assert a.foo == [1, 2, 3] | ||
25 | | ||
26 | mut arr_mut4 := a.bar | ||
| ~~ | ||
27 | arr_mut4[0] = 999 | ||
28 | assert a.bar == [1, 2, 3] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
struct Test { | ||
pub: | ||
bar []int = [1, 2, 3] | ||
pub mut: | ||
foo []int = [1, 2, 3] | ||
} | ||
|
||
fn main() { | ||
arr := [1, 2, 3] // declared as immutable! | ||
mut arr_mut := if true { arr } else { []int{} } | ||
mut arr_mut2 := match true { | ||
true { arr } | ||
else { [0] } | ||
} | ||
arr_mut[0] = 999 | ||
arr_mut2[1] = 999 | ||
println(arr) | ||
println(arr) | ||
assert arr == [1, 2, 3] | ||
|
||
a := Test{} | ||
mut arr_mut3 := a.foo | ||
arr_mut3[0] = 999 | ||
assert a.foo == [1, 2, 3] | ||
|
||
mut arr_mut4 := a.bar | ||
arr_mut4[0] = 999 | ||
assert a.bar == [1, 2, 3] | ||
|
||
_ := a.bar | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
module main | ||
|
||
// vtest vflags: -os wasm32_emscripten | ||
|
||
import platform_wrapper | ||
|
||
fn main() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps we can mention
outside unsafe{}
too, but that can wait till later.The CI is almost finished, and it is working well as it is.