mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
fix optional struct field assignment
This commit is contained in:
@ -73,7 +73,7 @@ fn test_opt_default() {
|
||||
|
||||
fn foo_ok() ?int {
|
||||
return 777
|
||||
}
|
||||
}
|
||||
|
||||
fn foo_str() ?string {
|
||||
return 'something'
|
||||
@ -81,7 +81,7 @@ fn foo_str() ?string {
|
||||
|
||||
fn test_q() {
|
||||
//assert foo_ok()? == true
|
||||
}
|
||||
}
|
||||
|
||||
struct Person {
|
||||
mut:
|
||||
@ -112,3 +112,15 @@ fn test_field_or() {
|
||||
}
|
||||
assert mytitle == 'default'
|
||||
}
|
||||
|
||||
struct Thing {
|
||||
mut:
|
||||
opt ?int
|
||||
}
|
||||
|
||||
fn test_opt_field() {
|
||||
mut t := Thing{}
|
||||
t.opt = 5
|
||||
val := t.opt or { return }
|
||||
assert val == 5
|
||||
}
|
||||
|
Reference in New Issue
Block a user