1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

find_field: use optional

This commit is contained in:
Alexander Medvednikov
2019-09-18 14:28:11 +03:00
parent d1500511e6
commit d180324413
2 changed files with 22 additions and 15 deletions

View File

@@ -1818,7 +1818,7 @@ fn (p mut Parser) dot(str_typ string, method_ph int) string {
// field
if has_field {
struct_field := if typ.name != 'Option' { p.table.var_cgen_name(field_name) } else { field_name }
field := p.table.find_field(typ, struct_field)
field := p.table.find_field(typ, struct_field) or { panic('field') }
if !field.is_mut && !p.has_immutable_field {
p.has_immutable_field = true
p.first_immutable_field = field
@@ -2786,7 +2786,7 @@ fn (p mut Parser) struct_init(typ string) string {
if field in inited_fields {
p.error('already initialized field `$field` in `$t.name`')
}
f := t.find_field(field)
f := t.find_field(field) or { panic('field') }
inited_fields << field
p.gen_struct_field_init(field)
p.check(.colon)