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 results triggered by dead code #23274

Closed
debilosaurus opened this issue Dec 26, 2024 · 1 comment · Fixed by #23285
Closed

Wrong results triggered by dead code #23274

debilosaurus opened this issue Dec 26, 2024 · 1 comment · Fixed by #23285
Labels
Bug This tag is applied to issues which reports bugs. Generics[T] Bugs/feature requests, that are related to the V generics. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.

Comments

@debilosaurus
Copy link

debilosaurus commented Dec 26, 2024

Describe the bug

Adding some unused code changes the result of "magnitude()".

Reproduction Steps

import math.vec

// start: dead code, toggle bug
type UnusedType = vec.Vec3[f32]
fn (n UnusedType) unused_function() f32 {
	return n.mul_scalar(2).magnitude()
}
// end: dead code

fn main() {
	// correct values: 0.8660254, 2.598076
	println(vec.Vec3[f32]{0.5,0.5,0.5}.magnitude())
	println(vec.Vec3[f32]{1.5,1.5,1.5}.magnitude())
}

Expected Behavior

0.8660254
2.598076

Current Behavior

0.0
2.449490

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.9 7eec8b1

Environment details (OS name and version, etc.)

https://play.vlang.io/p/f1b6730843

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.

Huly®: V_0.6-21708

@debilosaurus debilosaurus added the Bug This tag is applied to issues which reports bugs. label Dec 26, 2024
@felipensp
Copy link
Member

felipensp commented Dec 26, 2024

Checking the diff...

image

Using the following code commented vs uncommented

fn (n UnusedType) unused_function() {
	//n.mul_scalar(2)
}

@felipensp felipensp added Status: Confirmed This bug has been confirmed to be valid by a contributor. Generics[T] Bugs/feature requests, that are related to the V generics. Unit: cgen Bugs/feature requests, that are related to the default C generating backend. labels Dec 26, 2024
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. Generics[T] Bugs/feature requests, that are related to the V generics. Status: Confirmed This bug has been confirmed to be valid by a contributor. Unit: cgen Bugs/feature requests, that are related to the default C generating backend.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants