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 checker should not allow passing pointers for the values of option struct fields #19378

Closed
spytheman opened this issue Sep 18, 2023 · 0 comments · Fixed by #19380
Closed

V checker should not allow passing pointers for the values of option struct fields #19378

spytheman opened this issue Sep 18, 2023 · 0 comments · Fixed by #19380
Assignees
Labels
Bug This tag is applied to issues which reports bugs. 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. Unit: Type System Bugs/feature requests, that are related to the V types system.

Comments

@spytheman
Copy link
Member

spytheman commented Sep 18, 2023

Describe the bug

Only none, or a valid value from the respective type should be allowed for struct fields, typed as ?Type.

Currently, instead V also allows passing pointers to such values.

Reproduction Steps

struct Abc {
	name ?string
	age ?int
}

fn main(){
	age := 34
	name := 'Bilbo'
	a := Abc {age: &age}
	b := Abc {name: &name}
	dump(a)
	dump(b)
}

Expected Behavior

A checker error, telling me that age: &age is not allowed, and perhaps suggesting, that I pass age: age instead. Same, but for name: &name too.

Current Behavior

[s.v:11] a: Abc{
    name: Option(none)
    age: Option(-395964448)
}
[s.v:12] b: Abc{
    name: Option('')
    age: Option(none)
}

Possible Solution

No response

Additional Information/Context

No response

V version

latest v

Environment details (OS name and version, etc.)

Ubuntu 20.04

Important

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.

@spytheman spytheman added Bug This tag is applied to issues which reports bugs. Unit: Compiler Bugs/feature requests, that are related to the V compiler in general. Unit: Checker Bugs/feature requests, that are related to the type checker. Unit: Type System Bugs/feature requests, that are related to the V types system. labels Sep 18, 2023
@Delta456 Delta456 self-assigned this Sep 18, 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: 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. Unit: Type System Bugs/feature requests, that are related to the V types system.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants