Utilities for x/tools/go/analysis package.
gostaticanalysis / analysisutil Goto Github PK
View Code? Open in Web Editor NEWLibrary: Utilities for x/tools/go/analysis package
License: MIT License
Library: Utilities for x/tools/go/analysis package
License: MIT License
I am trying to use static analysis to detect functions that do not call "Close
". But I found an issue in CalledFrom
function.
CalledFrom
function can correctly detects that the case (1) is NG.
case (1):
func f() {
client.ReadOnlyTransaction() // want "NG"
}
However, in the case (2), the function cannot correctly detects that it is NG.
case (2):
func f() {
os.Open("xxx") //want "NG"
}
In the CalledFrom
function, identical
function is called to compare receiver
(types.Pointer
type) and the return value of called funtion (eg. os.Open()
).
In the case (1), client.ReadOnlyTransaction()
returns only one value, so the type of return value is (types.Pointer
).
However, in the case (2), os.Open()
returns two values, so the type of return value is (types.Tuple
).
Because of them, CalledFrom
cannot correctly detects the case (2) is NG.
I was recently trying to use analysisutil.CalledFrom
instead of the example in sqlrowsutil. However this does not work as expected. analysisutil seems to be close, but not the exact behavior as sqlrowsutil. Is this expected? The godocs and signatures exactly match, so the assumption is their behavior would match as well.
https://github.com/gostaticanalysis/sqlrows/blob/master/sqlrowsutil/util.go#L199
https://github.com/gostaticanalysis/analysisutil/blob/v0.7.1/call.go#L397
type res struct {}
func newRes() res {
return res{}
}
func (r res) close() {}
func test() {
r := newRes()
r.close() // CalledFrom returns false and false
}
call_test.go
does not work.
type res struct {}
func newRes() *res {
return &res{}
}
func (r *res) close() {}
func test() {
r := newRes() // CalledFrom return true and false
defer r.close()
func() {
func(r *res) {}(r)
}()
}
analysisutil.MethodOf(pass, mytype, "method") // return nil
MethodOf
should not use (*types.Func).Id
to compare the name instead of (*types.Func).Name
.
type res struct{}
func newRes() *res { return &res{} }
func (r *res) close() {}
func f() {
r := newRes() // want `NG` it works
_ = r
}
// embedded type
type res2 struct{ *res }
func newRes2() *res2 { return &res2{newRes()}}
func g() {
r := newRes2() // want `NG` but does not work
_ = r
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.