mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
ast: use multi return optional for find_scope_and_var
This commit is contained in:
parent
71ca553190
commit
602bc06bee
@ -21,23 +21,13 @@ pub fn new_scope(parent &Scope, start_pos int) &Scope {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct ScopeVar {
|
||||
pub:
|
||||
scope &Scope
|
||||
var Var
|
||||
}
|
||||
|
||||
// pub fn (s &Scope) find_scope_and_var(name string) ?(&Scope,Var) {
|
||||
pub fn (s &Scope) find_scope_and_var(name string) ?ScopeVar {
|
||||
pub fn (s &Scope) find_scope_and_var(name string) ?(&Scope,Var) {
|
||||
if name in s.vars {
|
||||
// return s,s.vars[name]
|
||||
return ScopeVar{
|
||||
s,s.vars[name]}
|
||||
return s,s.vars[name]
|
||||
}
|
||||
for sc := s; !isnil(sc.parent); sc = sc.parent {
|
||||
if name in sc.vars {
|
||||
return ScopeVar{
|
||||
sc,sc.vars[name]}
|
||||
return sc,sc.vars[name]
|
||||
}
|
||||
}
|
||||
return none
|
||||
|
@ -809,16 +809,11 @@ pub fn (c mut Checker) ident(ident mut ast.Ident) table.Type {
|
||||
}
|
||||
start_scope := c.file.scope.innermost(ident.pos.pos)
|
||||
mut found := true
|
||||
mut var_scope := &ast.Scope(0)
|
||||
mut var := ast.Var{}
|
||||
// var_scope,var = start_scope.find_scope_and_var(ident.name) or {
|
||||
mr := start_scope.find_scope_and_var(ident.name) or {
|
||||
var_scope,var := start_scope.find_scope_and_var(ident.name) or {
|
||||
found = false
|
||||
c.error('not found: $ident.name - POS: $ident.pos.pos', ident.pos)
|
||||
panic('')
|
||||
}
|
||||
var_scope = mr.scope
|
||||
var = mr.var
|
||||
if found {
|
||||
// update the variable
|
||||
// we need to do this here instead of var_decl since some
|
||||
|
Loading…
Reference in New Issue
Block a user