mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
ast: allow scope var shadowing
This commit is contained in:
parent
68ca8ab8a4
commit
483f0f408c
@ -106,18 +106,13 @@ pub fn (s mut Scope) register(name string, obj ScopeObject) {
|
||||
if name == '_' {
|
||||
return
|
||||
}
|
||||
if _ := s.find(name) {
|
||||
if name in s.objects {
|
||||
// println('existing obect: $name')
|
||||
return
|
||||
}
|
||||
s.objects[name] = obj
|
||||
}
|
||||
|
||||
pub fn (s mut Scope) register_force(name string, obj ScopeObject) {
|
||||
s.objects[name] = obj
|
||||
}
|
||||
|
||||
|
||||
pub fn (s &Scope) outermost() &Scope {
|
||||
mut sc := s
|
||||
for !isnil(sc.parent) {
|
||||
|
@ -140,11 +140,11 @@ fn (mut p Parser) match_expr() ast.MatchExpr {
|
||||
if var_name != '' {
|
||||
// Register a shadow variable with the actual type
|
||||
// (this replaces the old `it`)
|
||||
// TODO doesn't work right now
|
||||
p.scope.register(var_name, ast.Var{
|
||||
name: var_name
|
||||
typ: typ.to_ptr()
|
||||
})
|
||||
// TODO doesn't work right now (fixed, uncomment when merging)
|
||||
// p.scope.register(var_name, ast.Var{
|
||||
// name: var_name
|
||||
// typ: typ.to_ptr()
|
||||
// })
|
||||
// println(var_name)
|
||||
}
|
||||
} else {
|
||||
|
@ -757,8 +757,7 @@ fn (mut p Parser) index_expr(left ast.Expr) ast.IndexExpr {
|
||||
}
|
||||
|
||||
fn (mut p Parser) scope_register_it() {
|
||||
// force new 'it' even if it exists in parent scope
|
||||
p.scope.register_force('it', ast.Var{
|
||||
p.scope.register('it', ast.Var{
|
||||
name: 'it'
|
||||
pos: p.tok.position()
|
||||
is_used: true
|
||||
|
Loading…
Reference in New Issue
Block a user