1
0
mirror of https://github.com/golang/go synced 2024-11-17 03:04:44 -07:00

go/types,types2: add a test for const initializer panic

Updates #59603

Change-Id: Iff99f45a72a259b57b2ebbc6c0f9ed710add3ae3
Reviewed-on: https://go-review.googlesource.com/c/go/+/484376
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@google.com>
This commit is contained in:
Rob Findley 2023-04-13 10:22:46 -04:00 committed by Robert Findley
parent 0742e6dbc0
commit 1312d9e6da
2 changed files with 55 additions and 0 deletions

View File

@ -1564,6 +1564,33 @@ var _ = a.C2
makePkg("main", mainSrc) // don't crash when type-checking this package
}
func TestIssue59603(t *testing.T) {
imports := make(testImporter)
conf := Config{
Error: func(err error) { t.Log(err) }, // don't exit after first error
Importer: imports,
}
makePkg := func(path, src string) {
f := mustParse(path, src)
pkg, _ := conf.Check(path, []*syntax.File{f}, nil) // errors logged via conf.Error
imports[path] = pkg
}
const libSrc = `
package a
const C = foo
`
const mainSrc = `
package main
import "a"
const _ = a.C
`
makePkg("a", libSrc)
makePkg("main", mainSrc) // don't crash when type-checking this package
}
func TestLookupFieldOrMethodOnNil(t *testing.T) {
// LookupFieldOrMethod on a nil type is expected to produce a run-time panic.
defer func() {

View File

@ -1562,6 +1562,34 @@ var _ = a.C2
makePkg("main", mainSrc) // don't crash when type-checking this package
}
func TestIssue59603(t *testing.T) {
fset := token.NewFileSet()
imports := make(testImporter)
conf := Config{
Error: func(err error) { t.Log(err) }, // don't exit after first error
Importer: imports,
}
makePkg := func(path, src string) {
f := mustParse(fset, path, src)
pkg, _ := conf.Check(path, fset, []*ast.File{f}, nil) // errors logged via conf.Error
imports[path] = pkg
}
const libSrc = `
package a
const C = foo
`
const mainSrc = `
package main
import "a"
const _ = a.C
`
makePkg("a", libSrc)
makePkg("main", mainSrc) // don't crash when type-checking this package
}
func TestLookupFieldOrMethodOnNil(t *testing.T) {
// LookupFieldOrMethod on a nil type is expected to produce a run-time panic.
defer func() {