Skip to content

Commit

Permalink
go/types: set up correct type with NewAlias
Browse files Browse the repository at this point in the history
Change-Id: I4b035b3539c98e5b1442d1009d457cbc199b42ee
Reviewed-on: https://go-review.googlesource.com/32637
Reviewed-by: Matthew Dempsky <[email protected]>
  • Loading branch information
griesemer committed Nov 2, 2016
1 parent 5513f85 commit 627f4d8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/go/types/object.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,18 @@ func (*Func) isDependency() {} // a function may be a dependency of an initi
type Alias struct {
object
orig Object // aliased constant, type, variable, or function; never an alias
kind token.Token // token.CONST, token.TYPE, token.VAR, or token.FUNC (type-checking internal use only)
kind token.Token // token.CONST, token.TYPE, token.VAR, or token.FUNC (only needed during resolve phase)
}

func NewAlias(pos token.Pos, pkg *Package, name string, orig Object) *Alias {
return &Alias{object{pos: pos, pkg: pkg, name: name}, orig, token.ILLEGAL}
var typ Type = Typ[Invalid]
if orig != nil {
typ = orig.Type()
}
// No need to set a valid Alias.kind - that field is only used during identifier
// resolution (1st type-checker pass). We could store the field outside but it's
// easier to keep it here.
return &Alias{object{nil, pos, pkg, name, typ, 0, token.NoPos}, orig, token.ILLEGAL}
}

// Orig returns the aliased object, or nil if there was an error.
Expand Down
1 change: 1 addition & 0 deletions src/go/types/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,7 @@ func (check *Checker) collectObjects() {

case *ast.AliasSpec:
obj := NewAlias(s.Name.Pos(), pkg, s.Name.Name, nil)
obj.typ = nil // unresolved
obj.kind = d.Tok
check.declarePkgObj(s.Name, obj, &declInfo{file: fileScope, init: s.Orig})

Expand Down

0 comments on commit 627f4d8

Please sign in to comment.