diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 4c1084ea95..0e12b5b8e4 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -4041,18 +4041,17 @@ fn (mut c Checker) ident(mut node ast.Ident) ast.Type { // used inside its initialisation like: `struct Abc { x &Abc } ... const a = [ Abc{0}, Abc{unsafe{&a[0]}} ]!` // see vlib/v/tests/const_fixed_array_containing_references_to_itself_test.v if unsafe { c.const_var != 0 } && name == c.const_var.name { - if mut c.const_var.expr is ast.ArrayInit { - if c.const_var.expr.is_fixed && c.expected_type.nr_muls() > 0 { - elem_typ := c.expected_type.deref() - node.kind = .constant - node.name = c.const_var.name - node.info = ast.IdentVar{ - typ: elem_typ - } - // c.const_var.typ = elem_typ - node.obj = c.const_var - return c.expected_type + if mut c.const_var.expr is ast.ArrayInit && c.const_var.expr.is_fixed + && c.expected_type.nr_muls() > 0 { + elem_typ := c.expected_type.deref() + node.kind = .constant + node.name = c.const_var.name + node.info = ast.IdentVar{ + typ: elem_typ } + // c.const_var.typ = elem_typ + node.obj = c.const_var + return c.expected_type } c.error('cycle in constant `${c.const_var.name}`', node.pos) return ast.void_type @@ -4064,9 +4063,8 @@ fn (mut c Checker) ident(mut node ast.Ident) ast.Type { c.error('undefined ident: `_` (may only be used in assignments)', node.pos) } return ast.void_type - } - // second use - if node.kind in [.constant, .global, .variable] { + } else if node.kind in [.constant, .global, .variable] { + // second use info := node.info as ast.IdentVar typ := c.type_resolver.get_type_or_default(node, info.typ) // Got a var with type T, return current generic type @@ -4360,10 +4358,6 @@ fn (mut c Checker) ident(mut node ast.Ident) ast.Type { } } } - if c.table.known_type(node.name) { - // e.g. `User` in `json.decode(User, '...')` - return ast.void_type - } return ast.void_type }