Giter VIP home page Giter VIP logo

unitconst's People

Contributors

iwata avatar tenntenn avatar zchee avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

iwata

unitconst's Issues

May be flaky when used with multichecker

Sorry if you don't support multichecker. Please close this issue.

Environment

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"

How to reproduce

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.