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

checker: handle unknown fields in fail_if_immutable

This commit is contained in:
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 (
align_left = 1
align_right = 4
ALIGN_RIGHT = 4
)

View File

@ -44,6 +44,14 @@ pub:
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 {
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 {
.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 {
type_str := c.table.type_to_str(it.expr_type)
c.error('field `$it.field_name` of struct `${type_str}` is immutable', it.pos)