parser: cleanup check_cross_variables() (#10754)

pull/10772/head
yuyi 2021-07-12 17:10:42 +08:00 committed by GitHub
parent b5f1cf80a6
commit 581280e6fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 9 deletions

View File

@ -81,12 +81,12 @@ fn (mut p Parser) check_undefined_variables(exprs []ast.Expr, val ast.Expr) ? {
} }
fn (mut p Parser) check_cross_variables(exprs []ast.Expr, val ast.Expr) bool { fn (mut p Parser) check_cross_variables(exprs []ast.Expr, val ast.Expr) bool {
val_ := val val_str := val.str()
match val_ { match val {
ast.Ident { ast.Ident {
for expr in exprs { for expr in exprs {
if expr is ast.Ident { if expr is ast.Ident {
if expr.name == val_.name { if expr.name == val.name {
return true return true
} }
} }
@ -94,24 +94,24 @@ fn (mut p Parser) check_cross_variables(exprs []ast.Expr, val ast.Expr) bool {
} }
ast.IndexExpr { ast.IndexExpr {
for expr in exprs { for expr in exprs {
if expr.str() == val.str() { if expr.str() == val_str {
return true return true
} }
} }
} }
ast.InfixExpr { ast.InfixExpr {
return p.check_cross_variables(exprs, val_.left) return p.check_cross_variables(exprs, val.left)
|| p.check_cross_variables(exprs, val_.right) || p.check_cross_variables(exprs, val.right)
} }
ast.PrefixExpr { ast.PrefixExpr {
return p.check_cross_variables(exprs, val_.right) return p.check_cross_variables(exprs, val.right)
} }
ast.PostfixExpr { ast.PostfixExpr {
return p.check_cross_variables(exprs, val_.expr) return p.check_cross_variables(exprs, val.expr)
} }
ast.SelectorExpr { ast.SelectorExpr {
for expr in exprs { for expr in exprs {
if expr.str() == val.str() { if expr.str() == val_str {
return true return true
} }
} }