mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: var opt & temp []
& non array init error & bug notes
This commit is contained in:
parent
d1f653f9bd
commit
b4e5e36d4a
@ -508,6 +508,16 @@ pub fn (c mut Checker) array_init(array_init mut ast.ArrayInit) table.Type {
|
|||||||
// a = []
|
// a = []
|
||||||
if array_init.exprs.len == 0 {
|
if array_init.exprs.len == 0 {
|
||||||
type_sym := c.table.get_type_symbol(c.expected_type)
|
type_sym := c.table.get_type_symbol(c.expected_type)
|
||||||
|
if type_sym.kind != .array {
|
||||||
|
// c.error('array_init: cannot use `[]` with non array.')
|
||||||
|
c.error('array_init: cannot use `[]` with non array. (maybe: `[]Type` instead of `[]`)', array_init.pos)
|
||||||
|
return table.void_type
|
||||||
|
}
|
||||||
|
// TODO: seperate errors once bug is fixed with `x := if expr { ... } else { ... }`
|
||||||
|
// if c.expected_type == table.void_type {
|
||||||
|
// c.error('array_init: use `[]Type` instead of `[]`', array_init.pos)
|
||||||
|
// return table.void_type
|
||||||
|
// }
|
||||||
array_info := type_sym.array_info()
|
array_info := type_sym.array_info()
|
||||||
array_init.elem_type = array_info.elem_type
|
array_init.elem_type = array_info.elem_type
|
||||||
return c.expected_type
|
return c.expected_type
|
||||||
@ -865,22 +875,28 @@ pub fn (c mut Checker) ident(ident mut ast.Ident) table.Type {
|
|||||||
// first use
|
// first use
|
||||||
else if ident.kind == .unresolved {
|
else if ident.kind == .unresolved {
|
||||||
start_scope := c.file.scope.innermost(ident.pos.pos)
|
start_scope := c.file.scope.innermost(ident.pos.pos)
|
||||||
if var := start_scope.find_var(ident.name) {
|
if obj := start_scope.find(ident.name) {
|
||||||
mut typ := var.typ
|
match obj {
|
||||||
if typ == 0 {
|
ast.Var {
|
||||||
typ = c.expr(var.expr)
|
mut typ := it.typ
|
||||||
|
if typ == 0 {
|
||||||
|
typ = c.expr(it.expr)
|
||||||
|
}
|
||||||
|
is_optional := table.type_is(typ, .optional)
|
||||||
|
ident.kind = .variable
|
||||||
|
ident.info = ast.IdentVar{
|
||||||
|
typ: typ
|
||||||
|
is_optional: is_optional
|
||||||
|
}
|
||||||
|
it.typ = typ
|
||||||
|
// unwrap optional (`println(x)`)
|
||||||
|
if is_optional {
|
||||||
|
return table.type_set(typ, .unset)
|
||||||
|
}
|
||||||
|
return typ
|
||||||
|
}
|
||||||
|
else {}
|
||||||
}
|
}
|
||||||
is_optional := table.type_is(typ, .optional)
|
|
||||||
ident.kind = .variable
|
|
||||||
ident.info = ast.IdentVar{
|
|
||||||
typ: typ
|
|
||||||
is_optional: is_optional
|
|
||||||
}
|
|
||||||
// unwrap optional (`println(x)`)
|
|
||||||
if is_optional {
|
|
||||||
return table.type_set(typ, .unset)
|
|
||||||
}
|
|
||||||
return typ
|
|
||||||
}
|
}
|
||||||
// prepend mod to look for fn call or const
|
// prepend mod to look for fn call or const
|
||||||
mut name := ident.name
|
mut name := ident.name
|
||||||
|
Loading…
Reference in New Issue
Block a user