mirror of
https://github.com/golang/go.git
synced 2025-05-16 21:04:38 +00:00
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 <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
parent
73c7378e4d
commit
0dcdbc772e
@ -479,8 +479,8 @@ func (check *Checker) collectObjects() {
|
|||||||
func (check *Checker) resolveBaseTypeName(name *ast.Ident) *TypeName {
|
func (check *Checker) resolveBaseTypeName(name *ast.Ident) *TypeName {
|
||||||
var path []*TypeName
|
var path []*TypeName
|
||||||
for {
|
for {
|
||||||
// name must denote an object found in the current package
|
// name must denote an object found in the current package scope
|
||||||
// (it could be explicitly declared or dot-imported)
|
// (note that dot-imported objects are not in the package scope!)
|
||||||
obj := check.pkg.scope.Lookup(name.Name)
|
obj := check.pkg.scope.Lookup(name.Name)
|
||||||
if obj == nil {
|
if obj == nil {
|
||||||
return nil
|
return nil
|
||||||
@ -496,15 +496,9 @@ func (check *Checker) resolveBaseTypeName(name *ast.Ident) *TypeName {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// tname must have been explicitly declared
|
|
||||||
// (dot-imported objects are not in objMap)
|
|
||||||
tdecl := check.objMap[tname]
|
|
||||||
if tdecl == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// we're done if tdecl defined tname as a new type
|
// we're done if tdecl defined tname as a new type
|
||||||
// (rather than an alias)
|
// (rather than an alias)
|
||||||
|
tdecl := check.objMap[tname] // must exist for objects in package scope
|
||||||
if !tdecl.alias {
|
if !tdecl.alias {
|
||||||
return tname
|
return tname
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user