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

checker: fix generic comparison for conditional assignment (fix #19398) #19401

Merged
merged 1 commit into from
Sep 21, 2023

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Sep 21, 2023

This PR fix generic comparison for conditional assignment (fix #19398).

  • Fix generic comparison for conditional assignment.
  • Add test.
fn clip[N](x []N, min N, max N) []N {
	mut result := []N{cap: x.len}
	for value in x {
		result << if value < min {
			min
		} else if value > max {
			max
		} else {
			value
		}
	}
	return result
}

fn main() {
	a := [1, 2, 3, 4, 5]
	dump(a)
	b := clip(a, 2, 4)
	dump(b)
	assert b == [2, 2, 3, 4, 4]
}

PS D:\Test\v\tt1> v run .    
[.\\tt1.v:17] a: [1, 2, 3, 4, 5]
[.\\tt1.v:19] b: [2, 2, 3, 4, 4]

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. Thank you!

@spytheman spytheman merged commit baf5d8a into vlang:master Sep 21, 2023
46 checks passed
@yuyi98 yuyi98 deleted the fix_array_push_if_expr branch September 21, 2023 13:40
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.

Generic comparison fails for conditional assignment
2 participants