go.tools/go/types: package name must not be blank
Fixes golang/go#8077. LGTM=adonovan R=golang-codereviews, adonovan CC=golang-codereviews https://golang.org/cl/91640043
This commit is contained in:
parent
2afc128b30
commit
8df7a779db
|
@ -162,7 +162,11 @@ func (check *checker) initFiles(files []*ast.File) {
|
||||||
for i, file := range files {
|
for i, file := range files {
|
||||||
switch name := file.Name.Name; pkg.name {
|
switch name := file.Name.Name; pkg.name {
|
||||||
case "":
|
case "":
|
||||||
pkg.name = name
|
if name != "_" {
|
||||||
|
pkg.name = name
|
||||||
|
} else {
|
||||||
|
check.errorf(file.Name.Pos(), "invalid package name _")
|
||||||
|
}
|
||||||
fallthrough
|
fallthrough
|
||||||
|
|
||||||
case name:
|
case name:
|
||||||
|
|
|
@ -79,6 +79,7 @@ var tests = [][]string{
|
||||||
{"testdata/gotos.src"},
|
{"testdata/gotos.src"},
|
||||||
{"testdata/labels.src"},
|
{"testdata/labels.src"},
|
||||||
{"testdata/issues.src"},
|
{"testdata/issues.src"},
|
||||||
|
{"testdata/blank.src"},
|
||||||
}
|
}
|
||||||
|
|
||||||
var fset = token.NewFileSet()
|
var fset = token.NewFileSet()
|
||||||
|
|
|
@ -16,9 +16,13 @@ type Package struct {
|
||||||
fake bool // scope lookup errors are silently dropped if package is fake (internal use only)
|
fake bool // scope lookup errors are silently dropped if package is fake (internal use only)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewPackage returns a new Package for the given package path and name.
|
// NewPackage returns a new Package for the given package path and name;
|
||||||
|
// the name must not be the blank identifier.
|
||||||
// The package is not complete and contains no explicit imports.
|
// The package is not complete and contains no explicit imports.
|
||||||
func NewPackage(path, name string) *Package {
|
func NewPackage(path, name string) *Package {
|
||||||
|
if name == "_" {
|
||||||
|
panic("invalid package name _")
|
||||||
|
}
|
||||||
scope := NewScope(Universe, fmt.Sprintf("package %q", path))
|
scope := NewScope(Universe, fmt.Sprintf("package %q", path))
|
||||||
return &Package{path: path, name: name, scope: scope}
|
return &Package{path: path, name: name, scope: scope}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
// Copyright 2014 The Go Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a BSD-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package _ /* ERROR invalid package name */
|
Loading…
Reference in New Issue