vlang / v

Simple, fast, safe, compiled language for developing maintainable software. Compiles itself in <1s with zero library dependencies. Supports automatic C => V translation. https://vlang.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Appending reference to array of sumtype references generates a new memory address.

islonely opened this issue · comments

V doctor:

OS: linux, "Manjaro Linux"
Processor: 8 cpus, 64bit, little endian, Intel(R) Core(TM) i5-8350U CPU @ 1.70GHz
CC version: cc (GCC) 12.1.0

vexe mtime: 2022-06-22 13:56:16
is vroot writable: true
is vmodules writable: true
V full version: V 0.2.4 223b96a.585b514

Git version: git version 2.36.1
Git vroot status: weekly.2022.24-60-g585b5145-dirty
.git/config present: true
thirdparty/tcc status: thirdparty-linux-amd64 eee03626

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

struct Element {
	name       string
	value      string
	children   []&Node
	attributes []&Attribute

struct Attribute {
	name string
	value string

type Node = Element | Attribute

fn main() {
	mut parent := &Element{
		name: 'parent element'
	attr := &Attribute{'foo', 'bar'}
	parent.children << attr
	parent.attributes << attr

What did you expect to see?

Memory address of parent.children[0] should match that of attr.

What did you see instead?


I think it is right. attr will cast to Node, so the address will be changed.

I think you may be right.

ezoic increase your site revenue