mvdan/goreduce

panic: types.Check should not error here: main.go:8:2: undeclared name: fmt

vcabbage opened this issue · 5 comments

I was checking out your project and ran across this panic.

Built with go version go1.8.3 darwin/amd64, latest goreduce commit 126d2e99d.

Possibly related to #13?

Source:

package main

import "fmt"

var b []int

func main() {
	fmt.Println(a())
}

func a() string {
	_ = b[0]
	return "hello"
}

Command:
goreduce -match 'index out of range' -call main .

Output:

panic: types.Check should not error here: main.go:8:2: undeclared name: fmt [recovered]
	panic: types.Check should not error here: main.go:8:2: undeclared name: fmt

goroutine 1 [running]:
go/types.(*Checker).handleBailout(0xc420236000, 0xc420109a68)
	/Users/kale/goroots/go1.8/src/go/types/check.go:213 +0xa4
panic(0x127ade0, 0xc4200e3280)
	/Users/kale/goroots/go1.8/src/runtime/panic.go:489 +0x2cf
main.reduce.func1(0x13fdca0, 0xc4200e5770)
	/Users/kale/go/src/github.com/mvdan/goreduce/reduce.go:159 +0x1cd
go/types.(*Checker).err(0xc420236000, 0x39, 0xc420071a80, 0x14, 0x0)
	/Users/kale/goroots/go1.8/src/go/types/errors.go:78 +0x11c
go/types.(*Checker).errorf(0xc420236000, 0x39, 0x12dc9ba, 0x13, 0xc4201079e8, 0x1, 0x1)
	/Users/kale/goroots/go1.8/src/go/types/errors.go:86 +0x95
go/types.(*Checker).ident(0xc420236000, 0xc4200e6e80, 0xc420070240, 0x0, 0x0, 0x0, 0x0)
	/Users/kale/goroots/go1.8/src/go/types/typexpr.go:30 +0xfff
go/types.(*Checker).exprInternal(0xc420236000, 0xc4200e6e80, 0x13ffe60, 0xc420070240, 0x0, 0x0, 0x0)
	/Users/kale/goroots/go1.8/src/go/types/expr.go:989 +0x1aa5
go/types.(*Checker).rawExpr(0xc420236000, 0xc4200e6e80, 0x13ffe60, 0xc420070240, 0x0, 0x0, 0x0)
	/Users/kale/goroots/go1.8/src/go/types/expr.go:945 +0x8d
go/types.(*Checker).exprOrType(0xc420236000, 0xc4200e6e80, 0x13ffe60, 0xc420070240)
	/Users/kale/goroots/go1.8/src/go/types/expr.go:1524 +0x5f
go/types.(*Checker).selector(0xc420236000, 0xc4200e6e80, 0xc420070280)
	/Users/kale/goroots/go1.8/src/go/types/call.go:336 +0xb0
go/types.(*Checker).exprInternal(0xc420236000, 0xc4200e6e80, 0x14001a0, 0xc420070280, 0x0, 0x0, 0x0)
	/Users/kale/goroots/go1.8/src/go/types/expr.go:1180 +0x1fdd
go/types.(*Checker).rawExpr(0xc420236000, 0xc4200e6e80, 0x14001a0, 0xc420070280, 0x0, 0x0, 0x0)
	/Users/kale/goroots/go1.8/src/go/types/expr.go:945 +0x8d
go/types.(*Checker).exprOrType(0xc420236000, 0xc4200e6e80, 0x14001a0, 0xc420070280)
	/Users/kale/goroots/go1.8/src/go/types/expr.go:1524 +0x5f
go/types.(*Checker).call(0xc420236000, 0xc4200e6e80, 0xc4200e61c0, 0xc4200e2e82)
	/Users/kale/goroots/go1.8/src/go/types/call.go:15 +0x66
go/types.(*Checker).exprInternal(0xc420236000, 0xc4200e6e80, 0x13ffa60, 0xc4200e61c0, 0x0, 0x0, 0x106c3c1)
	/Users/kale/goroots/go1.8/src/go/types/expr.go:1375 +0x1e5d
go/types.(*Checker).rawExpr(0xc420236000, 0xc4200e6e80, 0x13ffa60, 0xc4200e61c0, 0x0, 0x0, 0x0)
	/Users/kale/goroots/go1.8/src/go/types/expr.go:945 +0x8d
go/types.(*Checker).stmt(0xc420236000, 0x0, 0x13ffca0, 0xc4200e2260)
	/Users/kale/goroots/go1.8/src/go/types/stmt.go:318 +0x4a32
go/types.(*Checker).stmtList(0xc420236000, 0x0, 0xc4200e2270, 0x1, 0x1)
	/Users/kale/goroots/go1.8/src/go/types/stmt.go:110 +0xb8
go/types.(*Checker).funcBody(0xc420236000, 0xc420072fa0, 0xc4200e2200, 0x4, 0xc4200e56b0, 0xc4200e42a0)
	/Users/kale/goroots/go1.8/src/go/types/stmt.go:42 +0x196
go/types.(*Checker).functionBodies(0xc420236000)
	/Users/kale/goroots/go1.8/src/go/types/resolver.go:443 +0xdf
go/types.(*Checker).checkFiles(0xc420236000, 0xc4200f0078, 0x1, 0x1, 0x0, 0x0)
	/Users/kale/goroots/go1.8/src/go/types/check.go:229 +0xf2
go/types.(*Checker).Files(0xc420236000, 0xc4200f0078, 0x1, 0x1, 0xc4200e5170, 0xc420070380)
	/Users/kale/goroots/go1.8/src/go/types/check.go:218 +0x49
go/types.(*Config).Check(0xc4200ec060, 0x7fff5fbff81e, 0x1, 0xc4200e6080, 0xc4200f0078, 0x1, 0x1, 0xc4200a36d0, 0xc4200a3770, 0x0, ...)
	/Users/kale/goroots/go1.8/src/go/types/api.go:349 +0x180
main.(*reducer).reduceLoop(0xc4200ec000, 0x0)
	/Users/kale/go/src/github.com/mvdan/goreduce/reduce.go:248 +0x165
main.reduce(0x7fff5fbff81e, 0x1, 0x7fff5fbff819, 0x4, 0x7fff5fbff800, 0x12, 0x13fd860, 0xc420088010, 0xc4200740b0, 0x0, ...)
	/Users/kale/go/src/github.com/mvdan/goreduce/reduce.go:170 +0x1434
main.main()
	/Users/kale/go/src/github.com/mvdan/goreduce/main.go:48 +0x113
mvdan commented

I can reproduce on tip. This is a weird one!

So it says fmt is not declared, as if it wasn't imported. But the source that go/types is working on should have the import, as all the changes made until that point are just replacing "hello" by "".

That reminded me of something I forgot to mention. Replacing "hello" with "" results in no panic, just:

could not reduce program
mvdan commented

That's probably just because the tool still sucks :) it doens't know how to inline funcs nor variables, so it would make sense that it would get stuck.

mvdan commented

The fix was rather simple. Thanks for reporting!

Wow, that was a quick. Thanks for the fix and for writing this tool!