v icon indicating copy to clipboard operation
v copied to clipboard

Warning about an Inner Struct lacking initialisation when it was initialised

Open thomas-mangin opened this issue 2 years ago • 0 comments

Describe the bug

The following code generates a warning when I think it should not

struct Inner {
	ptr &u8
}

struct Outter {
	Inner
mut:
	size int
}

fn new_outter() &Outter {
	return &Outter{
		ptr: vcalloc(1)
		size: 1
	}
}

fn main () {
	outter := new_outter()
	println(outter)
}

Expected Behavior

It does compile without warning

Current Behavior

❯ v run bug-emded.v
bug-emded.v:12:10: warning: reference field `Inner.ptr` must be initialized
   10 | 
   11 | fn new_outter() &Outter {
   12 |     return &Outter{
      |             ~~~~~~~
   13 |         ptr: vcalloc(1)
   14 |         size: 1
&Outter{
    Inner: Inner{
        ptr: &101063fe0
    }
    size: 1
}

Reproduction Steps

run or compile the code above

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.3.3 93a2ffa

Environment details (OS name and version, etc.)

V full version: V 0.3.3 3197ec1.93a2ffa
OS: macos, macOS, 13.2.1, 22D68
Processor: 10 cpus, 64bit, little endian, Apple M1 Max

getwd: /Users/thomas/Code/github.com/ze-core/network/bugs
vexe: /Users/thomas/Unix/local/v/v
vexe mtime: 2023-03-15 19:34:49

vroot: OK, value: /Users/thomas/Unix/local/v
VMODULES: NOT writable, value: /Users/thomas/Unix/data/v/modules
VTMP: OK, value: /tmp/v_501

Git version: git version 2.39.2
Git vroot status: weekly.2023.11-9-g93a2ffa9-dirty
.git/config present: true

CC version: Apple clang version 14.0.0 (clang-1400.0.29.202)
thirdparty/tcc status: thirdparty-macos-arm64 a668e5a0

thomas-mangin avatar Mar 15 '23 20:03 thomas-mangin