-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
structs containing references cannot be used in maps #20245
Labels
Bug
This tag is applied to issues which reports bugs.
Nicer V Errors
Bugs/feature requests, related to improving V error messages.
Unit: Checker
Bugs/feature requests, that are related to the type checker.
Unit: Compiler
Bugs/feature requests, that are related to the V compiler in general.
Comments
Note that this works if you give a default value for the a &int = unsafe { nil } |
@JalonSolov that solution is not acceptable for two reasons:
|
spytheman
added
Unit: Checker
Bugs/feature requests, that are related to the type checker.
Nicer V Errors
Bugs/feature requests, related to improving V error messages.
Unit: Compiler
Bugs/feature requests, that are related to the V compiler in general.
labels
Dec 21, 2023
This is intentional, to prevent inadvertency struct MyStruct {
a &int
b int
}
fn main() {
mut foo := map[string]MyStruct{}
println(*(foo[''].a))
} outputs:
Considering the reason given by @elliotchance, which is also sufficient, I wonder whether it is possible to add the notification of struct MyStruct {
a &int
b int
}
fn main() {
mut foo := unsafe { map[string]MyStruct{} }
} |
shove70
added a commit
to shove70/v
that referenced
this issue
Dec 22, 2023
shove70
added a commit
to shove70/v
that referenced
this issue
Dec 22, 2023
…d notifications at map initializing(fix vlang#20245)
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.
Nicer V Errors
Bugs/feature requests, related to improving V error messages.
Unit: Checker
Bugs/feature requests, that are related to the type checker.
Unit: Compiler
Bugs/feature requests, that are related to the V compiler in general.
Describe the bug
If a struct contains a reference and is used in a map the compiler always reports:
Reproduction Steps
Expected Behavior
The compiler should not raise a notice.
Current Behavior
An notice is raised.
Possible Solution
No response
Additional Information/Context
No response
V version
V 0.4.3 ed754cf
Environment details (OS name and version, etc.)
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.
The text was updated successfully, but these errors were encountered: