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

ast, checker: improved accessing map value that contain pointers requires an or {} block #20266

Merged
merged 1 commit into from Dec 25, 2023

Conversation

shove70
Copy link
Contributor

@shove70 shove70 commented Dec 25, 2023

  1. Finish any remaining work: checker: remove unnecessary struct ref field initialization checks and notifications at map initializing(fix #20245) #20251 (comment)
  2. Recursively checks whether the map value contains a pointer.
  3. Add tests.
struct Struct {
	field &int
}

fn main() {
	m := map[string][]Struct{}
	a := m['key']
	println(a)
}

outputs:

a.v:7:8: notice: accessing map value that contain pointers requires an `or {}` block outside `unsafe`
    5 | fn main() {
    6 |     m := map[string][]Struct{}
    7 |     a := m['key']
      |           ~~~~~~~
    8 |     println(a)
    9 | }
[]

Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work!

@spytheman spytheman merged commit 053a7a9 into vlang:master Dec 25, 2023
54 checks passed
@shove70 shove70 deleted the shove-patch-3 branch December 25, 2023 13:27
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.

None yet

2 participants