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

Confusing error message when trying to initialize an anonymous struct with {} #22498

Closed
zeozeozeo opened this issue Oct 12, 2024 · 0 comments · Fixed by #22534
Closed

Confusing error message when trying to initialize an anonymous struct with {} #22498

zeozeozeo opened this issue Oct 12, 2024 · 0 comments · Fixed by #22534
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.

Comments

@zeozeozeo
Copy link
Contributor

zeozeozeo commented Oct 12, 2024

Describe the bug

Running the code below, the compiler produces a confusing error message and a completely unrelated message just after.

Reproduction Steps

struct AStructName {
	foo int
	anon struct {
		bar int
	}
}

fn main() {
	s := AStructName{5, {}}
	println(s)
}

Expected Behavior

An error that says to use struct {} to initialize the anonymous struct.

Current Behavior

test.v:9:22: error: `{}` can not be used for initialising empty structs any more. Use `_VAnonStruct1{}` instead.
    7 |
    8 | fn main() {
    9 |     s := AStructName{5, {}}
      |                         ~~
   10 |     println(s)
   11 | }
test.v:9:22: error: `map{  }` (no value) used as value
    7 |
    8 | fn main() {
    9 |     s := AStructName{5, {}}
      |                         ~~
   10 |     println(s)
   11 | }

Possible Solution

Change the error message to suggest using struct {} to initialize the embedded struct.

Additional Information/Context

The code in the error message does work, which is a little bit weird:

struct AStructName {
	foo int
	anon struct {
		bar int
	}
}

fn main() {
	s := AStructName{5, _VAnonStruct1{}}
	println(s)
}

the above compiles and runs, but it probably shouldn't (since _VAnonStruct1 is a type defined by the compiler). Could be related to a different issue.

V version

V 0.4.8 ab862c4

Environment details (OS name and version, etc.)

V full version: V 0.4.8 469b56e.ab862c4
OS: windows, Microsoft Windows 10 Pro v19045 64-bit
Processor: 10 cpus, 64bit, little endian,

getwd: C:\Users\user\Downloads
vexe: C:\Users\user\Desktop\Code\v\v.exe
vexe mtime: 2024-10-12 07:01:18

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

Git version: git version 2.42.0.windows.1
Git vroot status: weekly.2024.41-16-gab862c42
.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 b425ac82

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.

@zeozeozeo zeozeozeo added the Bug This tag is applied to issues which reports bugs. label Oct 12, 2024
@Delta456 Delta456 self-assigned this Oct 12, 2024
@felipensp felipensp added the Status: Confirmed This bug has been confirmed to be valid by a contributor. label Oct 12, 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.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants