aboutsummaryrefslogtreecommitdiffstats
AgeCommit message (Collapse)Author
2023-05-18findLocalVarDeclarations: Move AssignStmt handling to functionTeddy Wing
Match the `varDeclarations` function splitting this into a more self-contained block. Also don't return in the loop to ensure we look at all assignments in `assignStmt`.
2023-05-18varDeclaration: Return all identifiers in declarationTeddy Wing
Declarations can include multiple identifiers. Return all of these from the function and rename it accordingly.
2023-05-18Find variable declarations in function closureTeddy Wing
Treat these as shadowed variables and ignore them.
2023-05-18Add test for shadowing declarationTeddy Wing
This doesn't pass yet.
2023-05-18Clean up checkShadowingTeddy Wing
* Add descriptive comments. * Remove old in-progress code. * Change the function name to `findLocalAssignments` which made more sense given what the function now does.
2023-05-18Ignore shadowed variablesTeddy Wing
In order to ignore shadowed variables, we first build a list of all local assignments in the closure, and ignore any ident in that list.
2023-05-18Create a new plan for checking shadowingTeddy Wing
2023-05-18Try to ignore shadowed assignmentsTeddy Wing
Not working yet. Does print the right thing, but since we're also matching `*ast.Ident`s, we must be getting the shadowed declarations as Idents and including them in the reported diagnostics.
2023-05-18Find shadowed variable assignmentsTeddy Wing
We don't want to report shadowed variables.
2023-05-17Separate `isVariableTypeSignature` conditionTeddy Wing
It doesn't need to be attached to the `funcScope` condition as it's a separate check. Wasn't thinking carefully when I added the check.
2023-05-17Add test for shadowingTeddy Wing
2023-05-17Ignore captured variables containing functionsTeddy Wing
2023-05-17function_argument: Add a test for local function variablesTeddy Wing
2023-05-17Add test for function argumentsTeddy Wing
Don't report captured function values: $ go test --- FAIL: Test (1.26s) analysistest.go:459: ./testdata/function_argument.go:5:3: unexpected diagnostic: captured reference callback in goroutine closure
2023-05-17Add note for package documentationTeddy Wing
2023-05-17Add note for version flagTeddy Wing
2023-05-17struct_reference.go: Test multiple diagnostics on one lineTeddy Wing
2023-05-17Add notes about false positives that should be correctedTeddy Wing
2023-05-16Add license (GNU GPLv3+)Teddy Wing
2023-05-16checkClosure: Move `funcScope` inside this functionTeddy Wing
It's not used in `run()`, so we can move it here.
2023-05-16checkClosure: Add function doc commentTeddy Wing
2023-05-16checkClosure: Clean up old codeTeddy Wing
* Remove old in-progress code now that we have a working implementation. * Add explanatory comments. * Remove `assignmentsInFunc()` which is unused.
2023-05-16run: Add a few explanatory commentsTeddy Wing
2023-05-16run: Clean up old codeTeddy Wing
Remove old unused in-progress code.
2023-05-16Report reference-type closure argumentsTeddy Wing
2023-05-16Get arguments of closure with `funcLit.Type.Params.List`Teddy Wing
Easier to use than `goStmt.Call.Args` because we don't have to handle both `*ast.Expr` and `*ast.UnaryExpr`.
2023-05-16Try to get the arguments of the closure from `goStmt.Call.Args`Teddy Wing
2023-05-16Ignore any identifier that isn't a *types.VarTeddy Wing
Otherwise we can get `*types.TypeName` identifiers, like the variable types in the closure's argument list. We only want to inspect variables.
2023-05-16Add notes for next things to add and fixTeddy Wing
These items don't pass our tests.
2023-05-16Ignore variables defined in the function closureTeddy Wing
This correctly ignores local variables.
2023-05-16Use scope test to report captured variablesTeddy Wing
Report all variables declared in an outer scope. This does match variables defined in the closure too. Will need to fix that.
2023-05-16Add automated testTeddy Wing
Follow `golang.org/x/tools/go/analysis/passes/testinggoroutine` to write the test runner: https://github.com/golang/tools/blob/1c9fe3f82c363b929ef7239ca0ad8a5dafbbcf05/go/analysis/passes/testinggoroutine/testinggoroutine_test.go Add "want" comments to test code for validation.
2023-05-16Rename module to `gopkg.teddywing.com/gocapturedrefrace`Teddy Wing
Decided not to use my personal Git host directly for the module, but a new domain specific to Go modules. This could allow me to host the code elsewhere using a vanity module name.
2023-05-16Ideas for using scope LookupParent to check if variable is localTeddy Wing
2023-05-16Add a note for the current goalTeddy Wing
2023-05-16Find variable in outer scopesTeddy Wing
For every identifier in the closure, check if it exists in an outer scope.
2023-05-16Add note about `(*types.Scope).LookupParent`Teddy Wing
2023-05-16Find a `pass.TypesInfo.Scopes[]` that's not nilTeddy Wing
If I had read the comment for `Scopes` in https://godocs.io/go/types#Info I would have known that only a subset of `ast.Node` can appear in the `Scopes` field. Tried ones until I ended up with valid scopes. Now that we have a valid scope, maybe we can find out if it's using variables not declared within that scope.
2023-05-16Idea for getting the scope of the closureTeddy Wing
Just results in nil.
2023-05-16Add note about getting function ScopeTeddy Wing
2023-05-16Add note about (*ast.CallExpr).ArgsTeddy Wing
Discovered this existed.
2023-05-16Trying to get `types.Scope` of function literalTeddy Wing
Not working, as `funcObj` is nil.
2023-05-16Print origin and scope information of closure variablesTeddy Wing
Debugging and ideas for getting variables defined in this closure's scope.
2023-05-16Use `pass.TypesInfo.Defs[ident]` to differentiate DEFINE/ASSIGNTeddy Wing
Got this idea from a question by zhizhixiong (https://stackoverflow.com/users/12073516/zhizhixiong) on Stack Overflow: https://stackoverflow.com/questions/66544145/how-to-find-the-declaration-of-an-ident-using-go-analysis This seems to correctly print defines and assigns. It doesn't print the `decl` variable though.
2023-05-15`(*AssignStmt).Tok` always appears to be token.DEFINETeddy Wing
2023-05-15assignmentsInFunc: Try checking `(*AssignStmt).Tok`Teddy Wing
This field could maybe tell us whether it was a `:=` assignment (token.DEFINE) or `=` (token.ASSIGN), but it seems like it's always `token.DEFINE`.
2023-05-15Try getting `GenDecl`s in closureTeddy Wing
Turns out this only gets declarations like: var decl string but not: decl := "a" Is there a way to get the above one too?
2023-05-15Add test for reference argumentsTeddy Wing
These should be reported as well, because they're shared references even though they're passed as arguments. This currently reports the variable name as "aStruct", will need to look into how to correct that.
2023-05-15Add a new test for struct methodsTeddy Wing
2023-05-15Idea for getting variable declarations instead of assignmentsTeddy Wing