Skip to content

Commit 44b4ab5

Browse files
committed
internal: phase out PkgInfo.IsAnonymous
Its logic can be very easily replicated with ast.File.PackageName, which already treats "_" as equal to a missing package name. Signed-off-by: Daniel Martí <[email protected]> Change-Id: If8e19bbb6d28d0cd91bfd157d53e49cd736c31e2 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1200970 TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Roger Peppe <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent d34eb57 commit 44b4ab5

File tree

3 files changed

+3
-9
lines changed

3 files changed

+3
-9
lines changed

internal/core/compile/compile.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ func (c *compiler) compileFiles(a []*ast.File) *adt.Vertex { // Or value?
275275
// - anything in an anonymous file
276276
//
277277
for _, f := range a {
278-
if p := internal.GetPackageInfo(f); p.IsAnonymous() {
278+
if f.PackageName() == "" {
279279
continue
280280
}
281281
for _, d := range f.Decls {

internal/core/runtime/resolve.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"cuelang.org/go/cue/ast"
2222
"cuelang.org/go/cue/build"
2323
"cuelang.org/go/cue/errors"
24-
"cuelang.org/go/internal"
2524
)
2625

2726
// TODO(resolve): this is also done in compile, do we need both?
@@ -32,7 +31,7 @@ func (r *Runtime) ResolveFiles(p *build.Instance) (errs errors.Error) {
3231
// may be linked to any top-level entry of any of the files.
3332
allFields := map[string]ast.Node{}
3433
for _, f := range p.Files {
35-
if p := internal.GetPackageInfo(f); p.IsAnonymous() {
34+
if f.PackageName() == "" {
3635
continue
3736
}
3837
for _, d := range f.Decls {
@@ -44,7 +43,7 @@ func (r *Runtime) ResolveFiles(p *build.Instance) (errs errors.Error) {
4443
}
4544
}
4645
for _, f := range p.Files {
47-
if p := internal.GetPackageInfo(f); p.IsAnonymous() {
46+
if f.PackageName() == "" {
4847
continue
4948
}
5049
err := resolveFile(idx, f, p, allFields)

internal/internal.go

-5
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,6 @@ type PkgInfo struct {
138138
Name string
139139
}
140140

141-
// IsAnonymous reports whether the package is anonymous.
142-
func (p *PkgInfo) IsAnonymous() bool {
143-
return p.Name == "" || p.Name == "_"
144-
}
145-
146141
func GetPackageInfo(f *ast.File) PkgInfo {
147142
for i, d := range f.Decls {
148143
switch x := d.(type) {

0 commit comments

Comments
 (0)