mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
compiler: Allow or
usage when assigning to struct fields. (#2893)
This commit is contained in:

committed by
Alexander Medvednikov

parent
79a02a4c09
commit
6349bd33d3
@ -75,6 +75,40 @@ fn foo_ok() ?int {
|
||||
return 777
|
||||
}
|
||||
|
||||
fn foo_str() ?string {
|
||||
return 'something'
|
||||
}
|
||||
|
||||
fn test_q() {
|
||||
//assert foo_ok()? == true
|
||||
}
|
||||
|
||||
struct Person {
|
||||
mut:
|
||||
name string
|
||||
age int
|
||||
title ?string
|
||||
}
|
||||
|
||||
fn test_field_or() {
|
||||
name := foo_str() or {
|
||||
'nada'
|
||||
}
|
||||
assert name == 'something'
|
||||
|
||||
mut p := Person {}
|
||||
p.name = foo_str() or {
|
||||
'nothing'
|
||||
}
|
||||
assert p.name == 'something'
|
||||
|
||||
p.age = foo_ok() or {
|
||||
panic('no age')
|
||||
}
|
||||
assert p.age == 777
|
||||
|
||||
mytitle := p.title or {
|
||||
'default'
|
||||
}
|
||||
assert mytitle == 'default'
|
||||
}
|
Reference in New Issue
Block a user