checker: handle unknown fields in fail_if_immutable

pull/4794/head
Alexander Medvednikov 2020-05-10 02:07:15 +02:00
parent 09f6cd6a75
commit 10da871743
3 changed files with 14 additions and 1 deletions

View File

@ -49,6 +49,7 @@ pub const (
pub const ( pub const (
align_left = 1 align_left = 1
align_right = 4
ALIGN_RIGHT = 4 ALIGN_RIGHT = 4
) )

View File

@ -44,6 +44,14 @@ pub:
status_code int status_code int
} }
pub fn new_request(method, url, data string) ?Request{
return Request{
method: method
url: url
data: data
}
}
pub fn get(url string) ?Response { pub fn get(url string) ?Response {
return fetch_with_method('GET', url, FetchConfig{}) return fetch_with_method('GET', url, FetchConfig{})
} }

View File

@ -523,7 +523,11 @@ fn (mut c Checker) fail_if_immutable(expr ast.Expr) {
match typ_sym.kind { match typ_sym.kind {
.struct_ { .struct_ {
struct_info := typ_sym.info as table.Struct struct_info := typ_sym.info as table.Struct
field_info := struct_info.get_field(it.field_name) field_info := struct_info.find_field(it.field_name) or {
type_str := c.table.type_to_str(it.expr_type)
c.error('unknown field `${type_str}.$it.field_name`', it.pos)
return
}
if !field_info.is_mut { if !field_info.is_mut {
type_str := c.table.type_to_str(it.expr_type) type_str := c.table.type_to_str(it.expr_type)
c.error('field `$it.field_name` of struct `${type_str}` is immutable', it.pos) c.error('field `$it.field_name` of struct `${type_str}` is immutable', it.pos)