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 aliases of fixed array infix expression (fix #22925) #22928

Merged
merged 1 commit into from
Nov 21, 2024

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Nov 21, 2024

This PR fix aliases of fixed array infix expression (fix #22925).

  • Fix aliases of fixed array infix expression.
  • Add test.
import encoding.binary

pub type Addr = [4]u8

pub fn (a Addr) u32() u32 {
	return binary.big_endian_u32_fixed(a)
}

pub fn (a Addr) == (oth Addr) bool {
	return a.u32() == oth.u32()
}

pub fn (a Addr) < (oth Addr) bool {
	return a.u32() < oth.u32()
}

fn main() {
	addr := Addr([u8(127), 0, 0, 1]!)

	assert addr == Addr([u8(127), 0, 0, 1]!)
	assert Addr([u8(127), 0, 0, 1]!) == addr

	assert addr == [u8(127), 0, 0, 1]!
	assert [u8(127), 0, 0, 1]! == addr

	assert addr < Addr([u8(127), 0, 0, 2]!)
	assert addr < [u8(127), 0, 0, 2]!
}

D:\Test\v\tt1> v run .

Huly®: V_0.6-21370

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 19ea71b into vlang:master Nov 21, 2024
72 checks passed
@yuyi98 yuyi98 deleted the fix_alias_of_fixed_array branch November 21, 2024 12:49
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.

C error on comparison fixed array with aliased fixed array with operator overloading
2 participants