Skip to content

Conversation

@yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Jan 13, 2025

This PR fix assigning option of array index (fix #23451).

  • Fix assigning option of array index.
  • Add test.
fn make_option() ?string {
	return none
}

fn main() {
	arr := [make_option()]
	unwrapped := arr[99] or { 'unknown' } // <- out of bounds access!
	println('... ${unwrapped}')
}

PS D:\Test\v\tt1> v run .
... Option('unknown')

@huly-for-github
Copy link

Connected to Huly®: V_0.6-21885

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 514a9a7 into vlang:master Jan 14, 2025
72 checks passed
@yuyi98 yuyi98 deleted the fix_array_of_option_index branch January 15, 2025 01:02
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.

Out-of-bounds access of array with or block doesn't return the value of the or block

3 participants