-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
linter: improve if-related implicit vars handling
This change attempts to improve handleIf behavior. We introduce implicit kind of vars to express automatically defined vars that can be handled in a special way. andWalker.varsToDelete are removed because we're running all branches in a separate block contexts. No extra cleanup is required. Changed code requires to evaluate if statement condition separately, so we can get variables defined inside it into the parent block context. assignWalker type does that. Fixes #369 Fixes #363 Fixes #370 Signed-off-by: Iskander Sharipov <quasilyte@gmail.com>
- Loading branch information
Showing
6 changed files
with
274 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package linter | ||
|
||
import ( | ||
"github.com/VKCOM/noverify/src/php/parser/node" | ||
"github.com/VKCOM/noverify/src/php/parser/node/expr/assign" | ||
"github.com/VKCOM/noverify/src/php/parser/walker" | ||
"github.com/VKCOM/noverify/src/solver" | ||
) | ||
|
||
// assignWalker handles assignments by pushing all defined variables | ||
// to the associated block scope. | ||
type assignWalker struct { | ||
b *BlockWalker | ||
} | ||
|
||
func (a *assignWalker) EnterNode(w walker.Walkable) (res bool) { | ||
b := a.b | ||
switch n := w.(type) { | ||
case *assign.Assign: | ||
switch v := n.Variable.(type) { | ||
case *node.Var, *node.SimpleVar: | ||
b.ctx.sc.ReplaceVar(v, solver.ExprTypeLocal(b.ctx.sc, b.r.st, n.Expression), "assign", true) | ||
} | ||
} | ||
return true | ||
} | ||
|
||
func (a *assignWalker) LeaveNode(w walker.Walkable) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.