Go-tools: simple: ssa: emitConv panics on go1.8 style type conversions

Created on 21 Mar 2017  路  4Comments  路  Source: dominikh/go-tools

ssa.emitConv (as used by gosimple) doesn't seem to handle the types struct conversions available in go1.8.

https://github.com/dominikh/go-tools/blob/master/ssa/emit.go#L170-L245

Even though gosimple recommends

should use type conversion instead of struct literal (S1016)

It panics when that advice is taken. The structs are identical except for their tags.

Stacktrace:

panic: in (*myProject/pkg).myMethod: cannot convert *t0 (myProject/myFirstStruct) to myProject/mySecondIdenticalStruct

goroutine 3420 [running]:
honnef.co/go/tools/ssa.emitConv(0xc427816000, 0x143f8a0, 0xc444745b00, 0x143b700, 0xc43ff297d0, 0xc444745b00, 0xc44472eb40)
    /Users/tonyghita/go/src/myProject/_tools/src/honnef.co/go/tools/ssa/emit.go:244 +0x9e5
honnef.co/go/tools/ssa.(*builder).expr0(0xc44472fd00, 0xc427816000, 0x143c180, 0xc42749e400, 0x7, 0x143b700, 0xc43ff297d0, 0x0, 0x0, 0xc44017b040, ...)
    /Users/tonyghita/go/src/myProject/_tools/src/honnef.co/go/tools/ssa/builder.go:573 +0x30f0
honnef.co/go/tools/ssa.(*builder).expr(0xc44472fd00, 0xc427816000, 0x143c180, 0xc42749e400, 0xdb0224cc0829d01, 0xd00000000000000)
    /Users/tonyghita/go/src/myProject/_tools/src/honnef.co/go/tools/ssa/builder.go:530 +0x299
honnef.co/go/tools/ssa.(*builder).emitCallArgs(0xc44472fd00, 0xc427816000, 0xc440310f30, 0xc42749e440, 0x0, 0x0, 0x0, 0xc42749e440, 0xc44472f088, 0x100ec98)
    /Users/tonyghita/go/src/myProject/_tools/src/honnef.co/go/tools/ssa/builder.go:906 +0x30e
honnef.co/go/tools/ssa.(*builder).setCall(0xc44472fd00, 0xc427816000, 0xc42749e440, 0xc444746c40)
    /Users/tonyghita/go/src/myProject/_tools/src/honnef.co/go/tools/ssa/builder.go:969 +0x11a
honnef.co/go/tools/ssa.(*builder).expr0(0xc44472fd00, 0xc427816000, 0x143c180, 0xc42749e440, 0x1, 0x143b840, 0x0, 0x0, 0x0, 0x8, ...)
    /Users/tonyghita/go/src/myProject/_tools/src/honnef.co/go/tools/ssa/builder.go:596 +0x334f
honnef.co/go/tools/ssa.(*builder).expr(0xc44472fd00, 0xc427816000, 0x143c180, 0xc42749e440, 0xc4446b3a20, 0xc4446b3ad0)
    /Users/tonyghita/go/src/myProject/_tools/src/honnef.co/go/tools/ssa/builder.go:530 +0x299
honnef.co/go/tools/ssa.(*builder).stmt(0xc44472fd00, 0xc427816000, 0x143c3c0, 0xc427cf5a90)
    /Users/tonyghita/go/src/myProject/_tools/src/honnef.co/go/tools/ssa/builder.go:1985 +0x3975
honnef.co/go/tools/ssa.(*builder).stmtList(0xc44472fd00, 0xc427816000, 0xc42897bc00, 0x9, 0x10)
    /Users/tonyghita/go/src/myProject/_tools/src/honnef.co/go/tools/ssa/builder.go:790 +0x61
honnef.co/go/tools/ssa.(*builder).stmt(0xc441d8fd00, 0xc427816000, 0x143c100, 0xc424e6df50)
    /Users/tonyghita/go/src/myProject/_tools/src/honnef.co/go/tools/ssa/builder.go:2102 +0x2df7
honnef.co/go/tools/ssa.(*builder).buildFunction(0xc441d8fd00, 0xc427816000)
    /Users/tonyghita/go/src/myProject/_tools/src/honnef.co/go/tools/ssa/builder.go:2195 +0x35c
honnef.co/go/tools/ssa.(*builder).buildFuncDecl(0xc441d8fd00, 0xc438eac840, 0xc424e6df80)
    /Users/tonyghita/go/src/myProject/_tools/src/honnef.co/go/tools/ssa/builder.go:2225 +0x12e
honnef.co/go/tools/ssa.(*Package).build(0xc438eac840)
    /Users/tonyghita/go/src/myProject/_tools/src/honnef.co/go/tools/ssa/builder.go:2345 +0x691
honnef.co/go/tools/ssa.(*Package).(honnef.co/go/tools/ssa.build)-fm()
    /Users/tonyghita/go/src/myProject/_tools/src/honnef.co/go/tools/ssa/builder.go:2260 +0x2a
sync.(*Once).Do(0xc438eac86c, 0xc440a42f98)
    /usr/local/opt/go/libexec/src/sync/once.go:44 +0xbe
honnef.co/go/tools/ssa.(*Package).Build(0xc438eac840)
    /Users/tonyghita/go/src/myProject/_tools/src/honnef.co/go/tools/ssa/builder.go:2260 +0x55
honnef.co/go/tools/ssa.(*Program).Build.func1(0xc440980ea0, 0xc438eac840)
    /Users/tonyghita/go/src/myProject/_tools/src/honnef.co/go/tools/ssa/builder.go:2244 +0x2b
created by honnef.co/go/tools/ssa.(*Program).Build
    /Users/tonyghita/go/src/myProject/_tools/src/honnef.co/go/tools/ssa/builder.go:2246 +0x141
bug

All 4 comments

Tracking the upstream bug at https://github.com/golang/go/issues/19646

A fix was submitted to the upstream https://go-review.googlesource.com/c/38452/
Can you pull it in before it's merged? Or will that cause issues?

I'll wait for that change to be properly reviewed.

Upstream couldn't be arsed to review the change yet; I've reviewed and merged it myself.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jadekler picture jadekler  路  3Comments

tallclair picture tallclair  路  3Comments

axcdnt picture axcdnt  路  3Comments

dominikh picture dominikh  路  3Comments

tamird picture tamird  路  3Comments