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

generics, checker: Wrong alias management in methods 2 #24012

Open
enghitalo opened this issue Mar 22, 2025 · 1 comment
Open

generics, checker: Wrong alias management in methods 2 #24012

enghitalo opened this issue Mar 22, 2025 · 1 comment
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@enghitalo
Copy link
Contributor

enghitalo commented Mar 22, 2025

Describe the bug

Wrong method check

Reproduction Steps

pub struct User {
	name   string
	age    int
	height f64
}

type Users = map[string]User

fn (mut decoder Decoder) decode_map[K, V](mut val map[K]V) ! {
	assert true
}

// Decoder represents a JSON decoder.
struct Decoder {
}

pub fn decode[T](val string) !T {

	mut decoder := Decoder{
	}

	mut result := T{}
	decoder.decode_value(mut result)!

	return result
}

fn (mut decoder Decoder) decode_value[T](mut val T) ! {
	 $if T.unaliased_typ is $map {
		decoder.decode_map(mut val)!
	 }
}

fn main() {
	decode[Users]('')!
	decode[map[string]User]('')!
}

Expected Behavior

not error

Current Behavior

Can't run code. The server returned an error:
code.v:30:26: error: cannot use `&Users` as `&map[Users]User` in argument 1 to `Decoder.decode_map`
   28 | fn (mut decoder Decoder) decode_value[T](mut val T) ! {
   29 |      $if T.unaliased_typ is $map {
   30 |         decoder.decode_map(mut val)!
      |                                ~~~
   31 |      }
   32 | }
Exited with error status 1

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.10 d629a01

Environment details (OS name and version, etc.)

Linux

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 Mar 22, 2025
Copy link

Connected to Huly®: V_0.6-22405

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

1 participant