mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
ckecker: cleanup ident() (#24691)
This commit is contained in:
parent
a9e9e05118
commit
c5c2c804b8
1 changed files with 12 additions and 18 deletions
|
@ -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]}} ]!`
|
// 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
|
||||||
node.info = ast.IdentVar{
|
node.info = ast.IdentVar{
|
||||||
typ: elem_typ
|
typ: elem_typ
|
||||||
}
|
|
||||||
// c.const_var.typ = elem_typ
|
|
||||||
node.obj = c.const_var
|
|
||||||
return c.expected_type
|
|
||||||
}
|
}
|
||||||
|
// 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)
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue