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

walker: skip EmptyExpr for now

This commit is contained in:
Alexander Medvednikov 2021-03-31 12:15:06 +03:00
parent 024787b01c
commit e2e7e5fd65
3 changed files with 14 additions and 3 deletions

View File

@ -637,7 +637,7 @@ pub fn (mut c Checker) struct_init(mut struct_init ast.StructInit) table.Type {
struct_init.fields[i].expected_type = info_field.typ
}
}
// Check uninitialized refs
// Check uninitialized refs/sum types
for field in info.fields {
if field.has_default_expr || field.name in inited_fields {
continue
@ -646,6 +646,14 @@ pub fn (mut c Checker) struct_init(mut struct_init ast.StructInit) table.Type {
c.error('reference field `${type_sym.name}.$field.name` must be initialized',
struct_init.pos)
}
// Do not allow empty uninitialized sum types
/*
sym := c.table.get_type_symbol(field.typ)
if sym.kind == .sum_type {
c.warn('sum type field `${type_sym.name}.$field.name` must be initialized',
struct_init.pos)
}
*/
// Check for `[required]` struct attr
if field.attrs.contains('required') && !struct_init.is_short {
mut found := false

View File

@ -155,7 +155,8 @@ fn (mut w Walker) exprs(exprs []ast.Expr) {
fn (mut w Walker) expr(node ast.Expr) {
match mut node {
ast.EmptyExpr {
panic('Walker: EmptyExpr')
// TODO make sure this doesn't happen
// panic('Walker: EmptyExpr')
}
ast.AnonFn {
w.fn_decl(mut node.decl)

View File

@ -247,7 +247,9 @@ fn (t &Table) register_aggregate_field(mut sym TypeSymbol, name string) ?Field {
mut agg_info := sym.info as Aggregate
// an aggregate always has at least 2 types
mut found_once := false
mut new_field := Field{}
mut new_field := Field{
// default_expr: ast.empty_expr()
}
for typ in agg_info.types {
ts := t.get_type_symbol(typ)
if type_field := t.find_field(ts, name) {