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 warning "reference field must be initialized" when directly initialize embedded struct #18376

Closed
i582 opened this issue Jun 8, 2023 · 0 comments · Fixed by #18385
Closed
Labels
Bug This tag is applied to issues which reports bugs. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.

Comments

@i582
Copy link
Contributor

i582 commented Jun 8, 2023

Describe the bug

Code: https://vosca.dev/p/8e06c54374

struct Embedded {
	a &int
}

fn new_embedded() Embedded {
	return Embedded{
		a: unsafe { nil }
	}
}

struct Outer {
	Embedded
}

fn main() {
	o := Outer{
		Embedded: new_embedded()
	}
	println(o)
}

Expected Behavior

No warnings

Current Behavior

Output:

code.v:16:7: warning: reference field `Outer.a` must be initialized
   14 | 
   15 | fn main() {
   16 |     o := Outer{
      |          ~~~~~~
   17 |         Embedded: new_embedded()
   18 |     }
code.v:16:7: warning: reference field `Embedded.a` must be initialized
   14 | 
   15 | fn main() {
   16 |     o := Outer{
      |          ~~~~~~
   17 |         Embedded: new_embedded()
   18 |     }

Reproduction Steps

Run code above

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.3.4 fc4c431.45f16a2

Environment details (OS name and version, etc.)

V full version: V 0.3.4 fc4c431.bcd5c91
OS: linux, Ubuntu 22.04.2 LTS
Processor: 2 cpus, 64bit, little endian, Intel(R) Xeon(R) CPU E5-2670 v2 @ 2.50GHz

getwd: /home/pmakhnev/playground
vexe: /home/pmakhnev/v/v
vexe mtime: 2023-06-08 00:00:08

vroot: OK, value: /home/pmakhnev/v
VMODULES: OK, value: /root/.vmodules
VTMP: OK, value: /tmp/v_0

Git version: git version 2.34.1
Git vroot status: weekly.2023.22-32-gbcd5c91b
.git/config present: true

CC version: cc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3
@i582 i582 added the Bug This tag is applied to issues which reports bugs. label Jun 8, 2023
@felipensp felipensp added the Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. label Jun 8, 2023
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. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants