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: wrong array arg cast on methods using []T as parameter #20033

Closed
enghitalo opened this issue Nov 29, 2023 · 2 comments
Closed

cgen: wrong array arg cast on methods using []T as parameter #20033

enghitalo opened this issue Nov 29, 2023 · 2 comments
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@enghitalo
Copy link
Contributor

enghitalo commented Nov 29, 2023

Describe the bug

Methods using []T as parameter with problem

Reproduction Steps

module main

struct Decoder {
}

pub fn (mut d Decoder) decode[T](mut val T) {
	d.decode_array[T](mut val)
	decode_array(mut val)
}

fn (mut d Decoder) decode_array[T](mut val []T) {
	println(T.name)
}

fn decode_array[T](mut val []T) {
	println(T.name)
}

fn main() {
	mut arraia := [1]
	mut d := Decoder{}

	d.decode(mut arraia)
}

Expected Behavior

int
int

Current Behavior

[]int
int

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.3 782bf86

Environment details (OS name and version, etc.)

Linux Ubuntu

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.

@enghitalo enghitalo added the Bug This tag is applied to issues which reports bugs. label Nov 29, 2023
@yuyi98
Copy link
Member

yuyi98 commented Nov 29, 2023

d.decode_array[T](mut val) should be d.decode_array(mut val).

struct Decoder {
}

pub fn (mut d Decoder) decode[T](mut val T) {
	d.decode_array(mut val)
	decode_array(mut val)
}

fn (mut d Decoder) decode_array[T](mut val []T) {
	println(T.name)
}

fn decode_array[T](mut val []T) {
	println(T.name)
}

fn main() {
	mut arraia := [1]
	mut d := Decoder{}

	d.decode(mut arraia)
}

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

@enghitalo
Copy link
Contributor Author

Thank you!!

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

No branches or pull requests

2 participants