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

Generic function pointer returns wrong output #21499

Open
lv37 opened this issue May 14, 2024 · 2 comments
Open

Generic function pointer returns wrong output #21499

lv37 opened this issue May 14, 2024 · 2 comments
Labels
Bug This tag is applied to issues which reports bugs.

Comments

@lv37
Copy link
Contributor

lv37 commented May 14, 2024

Describe the bug

module main

struct Wrapper {
	a int
}

fn test[T](a &T) Wrapper {
	$if T is int {
		return Wrapper{a}
	}
	return Wrapper{}
}

fn main() {
	a := 123
	println(test(a).a)
}

Reproduction Steps

Run the code above

Expected Behavior

123

Current Behavior

Prints a random number

-654598052

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.5 58a8fc6

Environment details (OS name and version, etc.)

V full version: V 0.4.5 b347f54.58a8fc6
OS: linux, Linux version 6.8.9-300.fc40.x86_64 (mockbuild@5f5c14101bdf4cb8942130379360ff7d) (gcc (GCC) 14.0.1 20240411 (Red Hat 14.0.1-0), GNU ld version 2.41-34.fc40) #1 SMP PREEMPT_DYNAMIC Thu May  2 18:59:06 UTC 2024
Processor: 4 cpus, 64bit, little endian, Intel(R) Core(TM) i5-4310U CPU @ 2.00GHz

getwd: /home/user/Projects/learncpp
vexe: /home/user/.local/lib/v/v
vexe mtime: 2024-05-13 20:51:27

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.45.0
Git vroot status: weekly.2024.14-312-g58a8fc6c
.git/config present: true

CC version: cc (GCC) 14.1.1 20240507 (Red Hat 14.1.1-1)
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 May 14, 2024
@StunxFS
Copy link
Contributor

StunxFS commented May 14, 2024

Adding a dereference prints the expected value:

struct Wrapper {
	a int
}

fn test[T](a &T) Wrapper {
	$if T is int {
		return Wrapper{*a} // <- here
	}
	return Wrapper{}
}

fn main() {
	a := 123
	println(test(a).a)
}

@felipensp
Copy link
Member

What do you think @medvednikov @spytheman ?

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

3 participants