Skip to content

Commit 0dcdbc7

Browse files
committed
go/types: fix internal documentation and strengthen assumptions
Imported (incl. dot-imported) objects are always in file scope, never in package scope. Fix misleading comment. Package-scope declared objects must have objMap entry by construction (of that map). Remove unnecessary check and corresponding misleading comment. Found while investigating solutions for @23203. Change-Id: Idadfdd1576681ae56e11daa27bdcee2c73733c41 Reviewed-on: https://go-review.googlesource.com/110916 Run-TryBot: Robert Griesemer <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Alan Donovan <[email protected]>
1 parent 73c7378 commit 0dcdbc7

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

src/go/types/resolver.go

+3-9
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,8 @@ func (check *Checker) collectObjects() {
479479
func (check *Checker) resolveBaseTypeName(name *ast.Ident) *TypeName {
480480
var path []*TypeName
481481
for {
482-
// name must denote an object found in the current package
483-
// (it could be explicitly declared or dot-imported)
482+
// name must denote an object found in the current package scope
483+
// (note that dot-imported objects are not in the package scope!)
484484
obj := check.pkg.scope.Lookup(name.Name)
485485
if obj == nil {
486486
return nil
@@ -496,15 +496,9 @@ func (check *Checker) resolveBaseTypeName(name *ast.Ident) *TypeName {
496496
return nil
497497
}
498498

499-
// tname must have been explicitly declared
500-
// (dot-imported objects are not in objMap)
501-
tdecl := check.objMap[tname]
502-
if tdecl == nil {
503-
return nil
504-
}
505-
506499
// we're done if tdecl defined tname as a new type
507500
// (rather than an alias)
501+
tdecl := check.objMap[tname] // must exist for objects in package scope
508502
if !tdecl.alias {
509503
return tname
510504
}

0 commit comments

Comments
 (0)