ckecker: cleanup ident() (#24691)

This commit is contained in:
Felipe Pena 2025-06-11 02:09:28 -03:00 committed by GitHub
parent a9e9e05118
commit c5c2c804b8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -4041,8 +4041,8 @@ 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]}} ]!` // 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 // 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 unsafe { c.const_var != 0 } && name == c.const_var.name {
if mut c.const_var.expr is ast.ArrayInit { if mut c.const_var.expr is ast.ArrayInit && c.const_var.expr.is_fixed
if c.const_var.expr.is_fixed && c.expected_type.nr_muls() > 0 { && c.expected_type.nr_muls() > 0 {
elem_typ := c.expected_type.deref() elem_typ := c.expected_type.deref()
node.kind = .constant node.kind = .constant
node.name = c.const_var.name node.name = c.const_var.name
@ -4053,7 +4053,6 @@ fn (mut c Checker) ident(mut node ast.Ident) ast.Type {
node.obj = c.const_var node.obj = c.const_var
return c.expected_type return c.expected_type
} }
}
c.error('cycle in constant `${c.const_var.name}`', node.pos) c.error('cycle in constant `${c.const_var.name}`', node.pos)
return ast.void_type 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) c.error('undefined ident: `_` (may only be used in assignments)', node.pos)
} }
return ast.void_type return ast.void_type
} } else if node.kind in [.constant, .global, .variable] {
// second use // second use
if node.kind in [.constant, .global, .variable] {
info := node.info as ast.IdentVar info := node.info as ast.IdentVar
typ := c.type_resolver.get_type_or_default(node, info.typ) typ := c.type_resolver.get_type_or_default(node, info.typ)
// Got a var with type T, return current generic type // 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 return ast.void_type
} }