You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using go/types' Check on the following program:
package p
import "unicode/utf8"
var foo = utf8.UTFMax
with a types.Context.Ident func results in the func being called for the UTFMax ident.
However, the types.Const object associated with the ident has a nil spec member and
therefore panics when .GetPos() is called on it.
The following test (place in go.exp/go/types/objects_test.go) reproduces this bug:
package types
import (
"go/ast"
"go/parser"
"go/token"
"testing"
)
func TestConstGetPos(t *testing.T) {
fset := token.NewFileSet()
file, _ := parser.ParseFile(fset, "test.go", `package p; import "unicode/utf8"; var foo = utf8.UTFMax`, 0)
objs := make([]Object, 0)
c := Context{
Ident: func(id *ast.Ident, obj Object) {
objs = append(objs, obj)
},
}
c.Check(fset, []*ast.File{file})
for _, obj := range objs {
obj.GetPos() // should not panic
}
}
The panic output is:
$ go test go.exp/go/types
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x8 pc=0x454fc0]
goroutine 7 [running]:
testing.func��004()
/home/sqs/src/go/src/pkg/testing/testing.go:341 +0xbc
go.exp/go/types.(*Const).GetPos(0xc2003efa50, 0x13)
/home/sqs/src/go.exp/go/types/objects.go:101 +0x20
go.exp/go/types.TestConstGetPos(0xc200431900)
/home/sqs/src/go.exp/go/types/objects_test.go:21 +0x247
testing.tRunner(0xc200431900, 0x71fee8)
/home/sqs/src/go/src/pkg/testing/testing.go:346 +0x8a
created by testing.RunTests
/home/sqs/src/go/src/pkg/testing/testing.go:426 +0x86b
goroutine 1 [chan receive]:
testing.RunTests(0x644028, 0x71fea0, 0x8, 0x8, 0x5f5001, ...)
/home/sqs/src/go/src/pkg/testing/testing.go:427 +0x88e
testing.Main(0x644028, 0x71fea0, 0x8, 0x8, 0x7250c0, ...)
/home/sqs/src/go/src/pkg/testing/testing.go:358 +0x8a
main.main()
go.exp/go/types/_test/_testmain.go:57 +0x9a
FAIL go.exp/go/types 0.244s
What is the expected output? Calling obj.GetPos() should return the Pos of the UTFMax
declaration.
What do you see instead? Calling obj.GetPos() causes a panic.
Which compiler are you using (5g, 6g, 8g, gccgo)? 6g
Which operating system are you using? Linux
Which version are you using? go version devel +0ab15b04070e Wed Mar 13 07:45:31 2013
-0700 linux/amd64
The text was updated successfully, but these errors were encountered:
by qslack:
The text was updated successfully, but these errors were encountered: