mirror of
https://github.com/Crocmagnon/fatcontext.git
synced 2024-11-21 23:48:10 +01:00
feat: also added support for multiple contexts
This commit is contained in:
parent
387c533fad
commit
c2c0e62d59
2 changed files with 13 additions and 5 deletions
|
@ -110,21 +110,21 @@ func findNestedContext(pass *analysis.Pass, node ast.Node, stmts []ast.Stmt) *as
|
|||
for _, stmt := range stmts {
|
||||
// Recurse if necessary
|
||||
if inner, ok := stmt.(*ast.BlockStmt); ok {
|
||||
found := findNestedContext(pass, inner, inner.List)
|
||||
found := findNestedContext(pass, node, inner.List)
|
||||
if found != nil {
|
||||
return found
|
||||
}
|
||||
}
|
||||
|
||||
if inner, ok := stmt.(*ast.IfStmt); ok {
|
||||
found := findNestedContext(pass, inner, inner.Body.List)
|
||||
found := findNestedContext(pass, node, inner.Body.List)
|
||||
if found != nil {
|
||||
return found
|
||||
}
|
||||
}
|
||||
|
||||
if inner, ok := stmt.(*ast.SwitchStmt); ok {
|
||||
found := findNestedContext(pass, inner, inner.Body.List)
|
||||
found := findNestedContext(pass, node, inner.Body.List)
|
||||
if found != nil {
|
||||
return found
|
||||
}
|
||||
|
@ -138,7 +138,7 @@ func findNestedContext(pass *analysis.Pass, node ast.Node, stmts []ast.Stmt) *as
|
|||
}
|
||||
|
||||
if inner, ok := stmt.(*ast.SelectStmt); ok {
|
||||
found := findNestedContext(pass, inner, inner.Body.List)
|
||||
found := findNestedContext(pass, node, inner.Body.List)
|
||||
if found != nil {
|
||||
return found
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ func findNestedContext(pass *analysis.Pass, node ast.Node, stmts []ast.Stmt) *as
|
|||
}
|
||||
|
||||
if assignStmt.Tok == token.DEFINE {
|
||||
break
|
||||
continue
|
||||
}
|
||||
|
||||
// allow assignment to non-pointer children of values defined within the loop
|
||||
|
|
8
testdata/src/example.go
vendored
8
testdata/src/example.go
vendored
|
@ -71,6 +71,14 @@ func example() {
|
|||
ctx = wrapContext(ctx)
|
||||
}
|
||||
}
|
||||
|
||||
for {
|
||||
ctx2 := context.Background()
|
||||
ctx = wrapContext(ctx) // want "nested context in loop"
|
||||
if doSomething() != nil {
|
||||
ctx2 = wrapContext(ctx2)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func wrapContext(ctx context.Context) context.Context {
|
||||
|
|
Loading…
Reference in a new issue