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

V error when not initializing ?&Type #19559

Closed
islonely opened this issue Oct 12, 2023 · 0 comments · Fixed by #19786
Closed

V error when not initializing ?&Type #19559

islonely opened this issue Oct 12, 2023 · 0 comments · Fixed by #19786
Labels
Bug This tag is applied to issues which reports bugs. Option Type Bugs/feature requests, that are related to `?Type`. Unit: Checker Bugs/feature requests, that are related to the type checker.

Comments

@islonely
Copy link
Contributor

islonely commented Oct 12, 2023

Describe the bug

V error when not setting struct's ?&Type field to none when Type contains a &Type2 field that needs initialized.

Reproduction Steps

struct Viewport {
mut:
	parent &Window
}

pub struct Window {
mut:
	desktop_viewport ?&Viewport
	phone_viewport   ?&Viewport
}

fn main() {
	_ := &Window{}
}

Expected Behavior

Expected code to compile with ?&Viewport set to none by default. No output.

Current Behavior

With the code above:

C:/Users/imado/Documents/test.v:13:8: error: reference field `Window.desktop_viewport.parent` must be initialized (part of struct `Viewport`)
   11 | 
   12 | fn main() {
   13 |     _ := &Window{}
      |           ~~~~~~~~
   14 | }
C:/Users/imado/Documents/test.v:13:8: error: reference field `Window.phone_viewport.parent` must be initialized (part of struct `Viewport`)
   11 | 
   12 | fn main() {
   13 |     _ := &Window{}
      |           ~~~~~~~~
   14 | }

When changing the fields to this it compiles and runs, but I get warnings about the default value being none already.

desktop_viewport ?&Viewport = none
phone_viewport   ?&Viewport = none
C:/Users/imado/Documents/test.v:8:32: warning: unnecessary default value of `none`: struct fields are zeroed by default
    6 | pub struct Window {
    7 | mut:
    8 |     desktop_viewport ?&Viewport = none
      |                                   ~~~~
    9 |     phone_viewport   ?&Viewport = none
   10 | }
C:/Users/imado/Documents/test.v:9:32: warning: unnecessary default value of `none`: struct fields are zeroed by default
    7 | mut:
    8 |     desktop_viewport ?&Viewport = none
    9 |     phone_viewport   ?&Viewport = none
      |                                   ~~~~
   10 | }
   11 |

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.2 37e5616.2af135d

Environment details (OS name and version, etc.)

V full version: V 0.4.2 37e5616.2af135d
OS: windows, Microsoft Windows 11 Pro v22621 64-bit
Processor: 16 cpus, 64bit, little endian, 

getwd: C:\Users\imado\Documents\cyberian_tiger
vexe: C:\Users\imado\v\v.exe
vexe mtime: 2023-10-12 22:43:22

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

Git version: git version 2.33.1.windows.1
Git vroot status: weekly.2023.41-5-g2af135d7
.git/config present: true

CC version: Error: 'cc' is not recognized as an internal or external command,
operable program or batch file.

thirdparty/tcc status: thirdparty-windows-amd64 e90c2620

Note

You can vote for this issue using the 👍 reaction. More votes increase the issue's priority for developers.

Take into account that only the 👍 reaction counts as a vote.
Only reactions to the issue itself will be counted as votes, not comments.

@islonely islonely added the Bug This tag is applied to issues which reports bugs. label Oct 12, 2023
@ArtemkaKun ArtemkaKun added Unit: cgen Bugs/feature requests, that are related to the default C generating backend. Option Type Bugs/feature requests, that are related to `?Type`. Unit: Checker Bugs/feature requests, that are related to the type checker. and removed Unit: cgen Bugs/feature requests, that are related to the default C generating backend. labels Oct 13, 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. Option Type Bugs/feature requests, that are related to `?Type`. Unit: Checker Bugs/feature requests, that are related to the type checker.
Projects
None yet
2 participants