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

Wrong cast when passing a map to a generic function #20089

Closed
lv37 opened this issue Dec 4, 2023 · 1 comment · Fixed by #20097
Closed

Wrong cast when passing a map to a generic function #20089

lv37 opened this issue Dec 4, 2023 · 1 comment · Fixed by #20097
Assignees
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@lv37
Copy link
Contributor

lv37 commented Dec 4, 2023

Describe the bug

module main

fn generic[A](a A) {
	expect_map(A(a))
}

fn expect_map[K, V](a map[K]V) {
	println(a)
}

fn main() {
	a := { 'a': 1 }
	b := { 1: 'a' }
	generic(a) // prints { &int(&'a'): &string(&1) }
	generic(b) // commenting this line makes the one above work as expected
}

Reproduction Steps

Run the above code

Expected Behavior

It should print:

{ 'a': 1 }
{ 1: 'a' }

Current Behavior

It prints:

{1757855728: ''}
{1: 'a'}

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.3 c7b7d5f

Environment details (OS name and version, etc.)

V full version: V 0.4.3 b347f54.c7b7d5f
OS: linux, Linux version 6.5.12-300.fc39.x86_64 (mockbuild@cda4963b6857459f9d1b40ea59f8a44a) (gcc (GCC) 13.2.1 20231011 (Red Hat 13.2.1-4), GNU ld version 2.40-13.fc39) #1 SMP PREEMPT_DYNAMIC Mon Nov 20 22:44:24 UTC 2023
Processor: 4 cpus, 64bit, little endian, Intel(R) Core(TM) i5-4310U CPU @ 2.00GHz

getwd: /home/user/Projects/v-testing/hypixel
vexe: /home/user/.local/lib/v/v
vexe mtime: 2023-12-04 16:35:57

vroot: OK, value: /home/user/.local/lib/v
VMODULES: OK, value: /home/user/.vmodules
VTMP: OK, value: /tmp/v_1002

Git version: git version 2.43.0
Git vroot status: weekly.2023.48-48-gc7b7d5f5
.git/config present: true

CC version: cc (GCC) 13.2.1 20231011 (Red Hat 13.2.1-4)
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3

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.

@lv37 lv37 added the Bug This tag is applied to issues which reports bugs. label Dec 4, 2023
@lv37 lv37 changed the title Wrong case when passing a map to a generic function Wrong cast when passing a map to a generic function Dec 4, 2023
@felipensp felipensp self-assigned this Dec 5, 2023
@felipensp
Copy link
Member

I've fixed it on the PR when using expect_map(a), i.e. without casting.

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.

2 participants