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

Cloning heap struct instance with spread operator creates invalid copy. #23048

Closed
daansystems opened this issue Dec 2, 2024 · 0 comments · Fixed by #23049
Closed

Cloning heap struct instance with spread operator creates invalid copy. #23048

daansystems opened this issue Dec 2, 2024 · 0 comments · Fixed by #23049
Assignees
Labels
Bug This tag is applied to issues which reports bugs. 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

@daansystems
Copy link

daansystems commented Dec 2, 2024

V doctor:

V full version: V 0.4.8 5c65e58.b383cce
OS: windows, Microsoft Windows 11 Pro v22631 64-bit
Processor: 24 cpus, 64bit, little endian, 

getwd: D:\vbug
vexe: C:\v\v.exe
vexe mtime: 2024-12-02 09:23:44

vroot: OK, value: C:\v
VMODULES: OK, value: C:\Users\info\.vmodules
VTMP: OK, value: C:\Users\info\AppData\Local\Temp\v_0

Git version: git version 2.42.0.windows.2
Git vroot status: weekly.2024.48-39-gb383cce3-dirty
.git/config present: true

CC version: Error: 'cc' is not recognized as an internal or external command,

operable program or batch file.


emcc version: Error: 'emcc' is not recognized as an internal or external command,

operable program or batch file.


thirdparty/tcc status: thirdparty-windows-amd64 b425ac82

What did you do?
./v -g -o vdbg cmd/v && ./vdbg src/main.v

module main

type Mat4 = [16]f32

@[heap]
struct GameObject {
mut:
	transform Mat4
}

@[heap]
struct Ship  {
	GameObject
}

fn Ship.new() &Ship {
	mut ship := &Ship{}
	return ship
}

fn (ship Ship) clone() &Ship {
	return &Ship{
		...ship
	}
}

fn main() {
	mut v1 := Ship.new()
	mut v2 := v1.clone()
	eprintln('v1=${v1.transform}\nv2=${v2.transform}')
}

What did you expect to see?

a correct clone of the object. Please note that adding mut will work correct:

fn (mut ship Ship) clone() &Ship {
	return &Ship{
		...ship
	}
}

What did you see instead?

v1=Mat4([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0])
v2=Mat4([1.0021261e+08, 1.0021261e+08, 1.0021261e+08, 1.0021261e+08, 1.0021261e+08, 1.0021261e+08, 1.0021261e+08, 1.0021261e+08, 1.0021261e+08, 1.0021261e+08, 1.0021261e+08, 1.0021261e+08, 1.0021261e+08, 1.0021261e+08, 1.0021261e+08, 1.0021261e+08])

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-21488

@daansystems daansystems changed the title Cloning struct instance with spread operator creates invalid copy. Cloning heap struct instance with spread operator creates invalid copy. Dec 2, 2024
@felipensp felipensp self-assigned this Dec 2, 2024
@felipensp felipensp added Bug This tag is applied to issues which reports bugs. 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. labels Dec 2, 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. 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