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

Figure out empty array [] argument for generic function #22843

Closed
jorgeluismireles opened this issue Nov 12, 2024 · 0 comments · Fixed by #22846
Closed

Figure out empty array [] argument for generic function #22843

jorgeluismireles opened this issue Nov 12, 2024 · 0 comments · Fixed by #22846
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@jorgeluismireles
Copy link

jorgeluismireles commented Nov 12, 2024

Describe the bug

Using empty array [] as argument of functions of type defined works. Do the same for generic functions.

Reproduction Steps

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
}

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

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

assert count[f64]([1.0,2.0]) == 2
assert count[f64]([]f64{}) == 0
assert count[f64]([]) == 0 // error: cannot use `[]T` as `[]f64` in argument 1 to `count`

Expected Behavior

In the code above figure out the argument of last line: count[f64]([]) instead requiring to write the larger form count[f64]([]f64{}).

Current Behavior

code.v:21:19: error: cannot use []T as []f64 in argument 1 to count

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.8 fe5609d

Environment details (OS name and version, etc.)

https://play.vlang.io/p/3f23d7bdd1

Note

You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.

Huly®: V_0.6-21288

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant