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 fixed array field init with default value (fix #22392) #22399

Merged
merged 3 commits into from
Oct 3, 2024

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Oct 3, 2024

This PR fix struct fixed array field init with default value (fix #22392).

  • Fix struct fixed array field init with default value.
  • Add test.
type Mat4 = [16]f32

pub fn mat4(x0 f32, x1 f32, x2 f32, x3 f32, x4 f32, x5 f32, x6 f32, x7 f32, x8 f32, x9 f32, x10 f32, x11 f32, x12 f32, x13 f32, x14 f32, x15 f32) Mat4 {
	return [
		x0,
		x1,
		x2,
		x3,
		x4,
		x5,
		x6,
		x7,
		x8,
		x9,
		x10,
		x11,
		x12,
		x13,
		x14,
		x15,
	]!
}

pub fn unit_m4() Mat4 {
	return mat4(f32(1), 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)
}

struct GameObject {
mut:
	transform Mat4 = unit_m4()
}

fn main() {
	p := GameObject{}
	println(p)
	assert p.transform[0] == 1.0
	assert p.transform[1] == 0.0
	assert p.transform[5] == 1.0
}

PS D:\Test\v\tt1> v run .    
GameObject{
    transform:     Mat4([1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0])
}

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 9851367 into vlang:master Oct 3, 2024
78 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants