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 fn call with empty array argument (fix #22843) #22846

Merged
merged 1 commit into from
Nov 13, 2024

Conversation

yuyi98
Copy link
Member

@yuyi98 yuyi98 commented Nov 13, 2024

This PR fix generic fn call with empty array argument (fix #22843).

  • Fix generic fn call with empty array argument.
  • Add test.
fn count_str(array []string) int {
	return array.len
}

fn count_int(array []int) int {
	return array.len
}

fn count[T](array []T) int {
	return array.len
}

fn main() {
	assert count_str(['one', 'two']) == 2
	assert count_str([]string{}) == 0
	assert count_str([]) == 0

	assert count_int([1, 2]) == 2
	assert count_int([]int{}) == 0
	assert count_int([]) == 0

	assert count[f64]([1.0, 2.0]) == 2
	assert count[f64]([]f64{}) == 0
	assert count[f64]([]) == 0

	assert count[int]([1, 2]) == 2
	assert count[int]([]int{}) == 0
	assert count[int]([]) == 0
}

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

Huly®: V_0.6-21291

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 1a9dab2 into vlang:master Nov 13, 2024
71 checks passed
@yuyi98 yuyi98 deleted the fix_generic_fn_with_array_arg branch November 13, 2024 08:15
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.

Figure out empty array [] argument for generic function
2 participants