From bd833deef35910c781297324c7cc9141951abdf9 Mon Sep 17 00:00:00 2001 From: Alexander Medvednikov Date: Thu, 12 Dec 2019 20:32:55 +0300 Subject: [PATCH] assoc: verify the field exists and verify the type --- vlib/compiler/parser.v | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/vlib/compiler/parser.v b/vlib/compiler/parser.v index 4c299e635d..df291faaa6 100644 --- a/vlib/compiler/parser.v +++ b/vlib/compiler/parser.v @@ -2262,13 +2262,19 @@ fn (p mut Parser) assoc() string { } p.check(.pipe) p.gen('($var.typ){') + typ := p.table.find_type(var.typ) mut fields := []string// track the fields user is setting, the rest will be copied from the old object for p.tok != .rcbr { field := p.check_name() + //if !typ.has_field(field) { + f := typ.find_field(field) or { + p.error('`$typ.name` has no field `$field`') + exit(1) + } fields << field p.gen('.$field = ') p.check(.colon) - p.bool_expression() + p.check_types(p.bool_expression(), f.typ) p.gen(',') if p.tok != .rcbr { p.check(.comma) @@ -2276,8 +2282,7 @@ fn (p mut Parser) assoc() string { p.fgen_nl() } // Copy the rest of the fields - T := p.table.find_type(var.typ) - for ffield in T.fields { + for ffield in typ.fields { f := ffield.name if f in fields { continue