gostaticanalysis / unitconst Goto Github PK
View Code? Open in Web Editor NEWAnalyzer: unitconst finds using untyped constant as specified type
License: MIT License
Analyzer: unitconst finds using untyped constant as specified type
License: MIT License
Sorry if you don't support multichecker. Please close this issue.
bash-5.1$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/heijo/Library/Caches/go-build"
GOENV="/Users/heijo/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/heijo/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/heijo/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.15.6/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.15.6/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/heijo/Desktop/migrate/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/62/nry11cv13n9_4s_sq9y63l1h0000gn/T/go-build149661103=/tmp/go-build -gno-record-gcc-switches -fno-common"
I reproduced this issue in the golang-migrate/migrate
.
Some projects did not reproduce.
git clone https://github.com/golang-migrate/migrate
cd migrate/
mkdir -p ./tmp/tmpmain
cat <<EOF> ./tmp/tmpmain/main.go
package main
import (
"github.com/gostaticanalysis/unitconst"
"golang.org/x/tools/go/analysis/multichecker"
)
func main() {
multichecker.Main(
unitconst.Analyzer,
)
}
EOF
go mod tidy
go run ./tmp/tmpmain ./...
bash-5.1$ go run ./tmp/tmpmain/ ./...
panic: runtime error: index out of range [0] with length 0
goroutine 6234 [running]:
github.com/gostaticanalysis/unitconst.(*analyzer).init(0xc00018a6c0, 0xc001637e00, 0x1f3ac18, 0x10)
/Users/heijo/go/pkg/mod/github.com/gostaticanalysis/[email protected]/unitconst.go:140 +0x49f
github.com/gostaticanalysis/unitconst.(*analyzer).run(0xc00018a6c0, 0xc001637e00, 0x12c743f, 0x125, 0x126, 0xc001401f08)
/Users/heijo/go/pkg/mod/github.com/gostaticanalysis/[email protected]/unitconst.go:70 +0x39
golang.org/x/tools/go/analysis/internal/checker.(*action).execOnce(0xc0050f5180)
/Users/heijo/go/pkg/mod/golang.org/x/[email protected]/go/analysis/internal/checker/checker.go:690 +0x87e
sync.(*Once).doSlow(0xc0050f5180, 0xc000f85f90)
/usr/local/Cellar/go/1.15.6/libexec/src/sync/once.go:66 +0xec
sync.(*Once).Do(...)
/usr/local/Cellar/go/1.15.6/libexec/src/sync/once.go:57
golang.org/x/tools/go/analysis/internal/checker.(*action).exec(0xc0050f5180)
/Users/heijo/go/pkg/mod/golang.org/x/[email protected]/go/analysis/internal/checker/checker.go:579 +0x65
golang.org/x/tools/go/analysis/internal/checker.execAll.func1(0xc0050f5180)
/Users/heijo/go/pkg/mod/golang.org/x/[email protected]/go/analysis/internal/checker/checker.go:567 +0x34
created by golang.org/x/tools/go/analysis/internal/checker.execAll
/Users/heijo/go/pkg/mod/golang.org/x/[email protected]/go/analysis/internal/checker/checker.go:573 +0x125
exit status 2
other outputs
bash-5.1$ go run ./tmp/tmpmain/ ./...
unitconst: a.go:5:22: undeclared name: t11390400
exit status 1
bash-5.1$ go run ./tmp/tmpmain/ ./...
unitconst: a.go:7:23: undeclared name: time
exit status 1
bash-5.1$ go run ./tmp/tmpmain/ ./...
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x12df952]
goroutine 6200 [running]:
github.com/gostaticanalysis/unitconst.(*analyzer).hash(0xc00018a720, 0x14afb40, 0x1699de0, 0xc003835cb0)
/Users/heijo/go/pkg/mod/github.com/gostaticanalysis/[email protected]/unitconst.go:151 +0x92
github.com/gostaticanalysis/unitconst.(*analyzer).constExprs.func1(0x14aef80, 0xc0025bb1c0, 0x1, 0xffffffffffffff01)
/Users/heijo/go/pkg/mod/github.com/gostaticanalysis/[email protected]/unitconst.go:224 +0x430
golang.org/x/tools/go/ast/inspector.(*Inspector).Nodes(0xc003abbb00, 0x0, 0x0, 0x0, 0xc001355a78)
/Users/heijo/go/pkg/mod/golang.org/x/[email protected]/go/ast/inspector/inspector.go:100 +0xc2
github.com/gostaticanalysis/unitconst.(*analyzer).constExprs(0xc00018a720, 0xc001a28d80)
/Users/heijo/go/pkg/mod/github.com/gostaticanalysis/[email protected]/unitconst.go:190 +0x85
github.com/gostaticanalysis/unitconst.(*analyzer).run(0xc00018a720, 0xc001a28d80, 0x10, 0x13da080, 0x5b9fbcc2ca8c0701, 0xc003aabb90)
/Users/heijo/go/pkg/mod/github.com/gostaticanalysis/[email protected]/unitconst.go:78 +0x65
golang.org/x/tools/go/analysis/internal/checker.(*action).execOnce(0xc003c223c0)
/Users/heijo/go/pkg/mod/golang.org/x/[email protected]/go/analysis/internal/checker/checker.go:690 +0x87e
sync.(*Once).doSlow(0xc003c223c0, 0xc00118df90)
/usr/local/Cellar/go/1.15.6/libexec/src/sync/once.go:66 +0xec
sync.(*Once).Do(...)
/usr/local/Cellar/go/1.15.6/libexec/src/sync/once.go:57
golang.org/x/tools/go/analysis/internal/checker.(*action).exec(0xc003c223c0)
/Users/heijo/go/pkg/mod/golang.org/x/[email protected]/go/analysis/internal/checker/checker.go:579 +0x65
golang.org/x/tools/go/analysis/internal/checker.execAll.func1(0xc003c223c0)
/Users/heijo/go/pkg/mod/golang.org/x/[email protected]/go/analysis/internal/checker/checker.go:567 +0x34
created by golang.org/x/tools/go/analysis/internal/checker.execAll
/Users/heijo/go/pkg/mod/golang.org/x/[email protected]/go/analysis/internal/checker/checker.go:573 +0x125
exit status 2
bash-5.1$ go run ./tmp/tmpmain/ ./...
unitconst: a.go:5:23: undeclared name: t14374528
unitconst: a.go:5:22: undeclared name: t14374528
/Users/heijo/Desktop/migrate/migrate.go:29:26: must not use a untyped constant without a unit
exit status 1
bash-5.1$ go run ./tmp/tmpmain/ ./...
unitconst: a.go:5:23: undeclared name: t12940928
/Users/heijo/Desktop/migrate/database/cassandra/cassandra.go:99:20: must not use a untyped constant without a unit
/Users/heijo/Desktop/migrate/database/mongodb/mongodb.go:373:59: must not use a untyped constant without a unit
exit status 1
time.Sleep(0)
Currently, unitconst supports only types which are defined at the standard package.
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.