Open
Description
Describe the bug
I think is a bug otherwise I want to know alternatives.
- Struct
Data
implements interfaceCols
with functioncols() string
- There is a function
fn print_first_last(cols []Cols) { }
- An array of
[]Data{ len:3 }
is passed toprint_first_last
function but is not accepted.
Nor []&Data{} is accepted.
Reproduction Steps
pub interface Cols {
cols() string
}
pub fn print_first_last(cols []Cols) {
// ...
}
struct Data implements Cols {
// data fields
}
fn (c Data) cols() string { // implementation
return '...'
}
fn main() {
data := []Data{ len:3 }
print_first_last(data)
}
Expected Behavior
[]Data{}
passed to print_first_last(c [] Cols)
should be accepted since Data
implements Cols
and array of implementation should be accepted also.
Current Behavior
Running code...
Can't run code. The server returned an error:
code.v:19:19: error: cannot use `[]Data` as `[]Cols` in argument 1 to `print_first_last`
17 | fn main() {
18 | data := []Data{ len:3 }
19 | print_first_last(data)
| ~~~~
20 | }
Exited with error status 1
Please try again.
Possible Solution
No response
Additional Information/Context
No response
V version
V 0.4.9 b91bbad
Environment details (OS name and version, etc.)
https://play.vlang.io/p/d6a82f4ac2
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.