-
-
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
Option smartcast after non-option assignment #23611
Comments
Connected to Huly®: V_0.6-22036 |
The if foo == none {
foo = Foo.init()
foo.test = true
} since after |
I only can get rid of warnings and errors until pub struct Foo {
mut:
test bool
}
struct Bar {
mut:
foo ?Foo
}
fn (mut b Bar) what() {
if b.foo != none {
b.foo.test = true
}
}
fn main() {
mut b1 := Bar{ } // foo remains none
b1.what()
println('${b1.foo}') // Option(none)
mut b2 := Bar{ foo:Foo{} }
b2.what()
println('${b2.foo}') // Option(Foo{test:true})
} |
That doesn't solve the issue unfortunately |
No, it doesn't. That will have to be done with a bug fix. The workaround, as @spytheman said yesterday in discord, would be to create a new variable, and assign that to if foo == none {
mut newfoo := Foo.init()
newfoo.test = true
foo = newfoo
} |
V version: V 0.4.9 a6a8e4c, press to see full `v doctor` output
What did you do?
./v -g -o vdbg cmd/v && ./vdbg -cg testit.v && S:\vProjects\testit\testit.exe
What did you see?
What did you expect to see?
clean build
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: