Skip to content

generics, checker: Wrong alias management in methods 1 #24011

@enghitalo

Description

@enghitalo

Describe the bug

wrong checker error in methods

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
}

struct Decoder {
}

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

	mut decoder := Decoder{
	}

	mut result := T{}
	$if T.unaliased_typ is $map {
		decoder.decode_map(mut result)!
	}

	return result
}

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

Expected Behavior

assert pass

Current Behavior

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 |      } $else {
   32 |
Exited with error status 1
Please try again.

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugThis tag is applied to issues which reports bugs.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions