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

cgen: fix struct field init with optional fixed array (fix #23195) #23199

Merged
merged 2 commits into from
Dec 18, 2024

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Dec 18, 2024

This PR fix struct field init with optional fixed array (fix #23195, fix #23193).

  • Fix struct field init with optional fixed array.
  • Add test.
type Arr = [4]u8

struct Foo {
	bar int
	baz ?Arr
}

fn main() {
	f1 := Foo{
		bar: 1
		baz: Arr([u8(5), 4, 3, 2]!)
	}
	println(f1)
	assert f1.baz as Arr == [u8(5), 4, 3, 2]!

	f2 := Foo{
		bar: 1
		baz: ?Arr(none)
	}
	println(f2)
	assert f2.bar == 1
	assert f2.baz == none

	arr := Arr([u8(5), 4, 3, 2]!)
	f3 := Foo{
		bar: 1
		baz: arr
	}
	println(f3)
	assert f3.bar == 1
	assert f3.baz as Arr == [u8(5), 4, 3, 2]!
}

PS D:\Test\v\tt1> v run .
Foo{
    bar: 1
    baz: Option(    Arr([5, 4, 3, 2]))
}
Foo{
    bar: 1
    baz: Option(none)
}
Foo{
    bar: 1
    baz: Option(    Arr([5, 4, 3, 2]))
}

Huly®: V_0.6-21636

@felipensp
Copy link
Member

Excellent, @yuyi98! Thanks.

@spytheman spytheman merged commit e8ee207 into vlang:master Dec 18, 2024
72 checks passed
@yuyi98 yuyi98 deleted the fix_struct_field_optional branch December 19, 2024 01:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants