Commit b5203be8 authored by Robert Griesemer's avatar Robert Griesemer

go/importer: implement importing of exported aliases

Fixes #17592.

Change-Id: I914fa8c0729012990878b6e5c3e99b0f9b0e2be8
Reviewed-on: https://go-review.googlesource.com/32350
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarAlan Donovan <adonovan@google.com>
parent 49b2dd58
...@@ -222,22 +222,33 @@ func (p *importer) declare(obj types.Object) { ...@@ -222,22 +222,33 @@ func (p *importer) declare(obj types.Object) {
} }
func (p *importer) obj(tag int) { func (p *importer) obj(tag int) {
var aliasPos token.Pos
var aliasName string
if tag == aliasTag {
aliasPos = p.pos()
aliasName = p.string()
tag = p.tagOrIndex()
}
var obj types.Object
switch tag { switch tag {
case constTag: case constTag:
pos := p.pos() pos := p.pos()
pkg, name := p.qualifiedName() pkg, name := p.qualifiedName()
typ := p.typ(nil) typ := p.typ(nil)
val := p.value() val := p.value()
p.declare(types.NewConst(pos, pkg, name, typ, val)) obj = types.NewConst(pos, pkg, name, typ, val)
p.declare(obj)
case typeTag: case typeTag:
_ = p.typ(nil) obj = p.typ(nil).(*types.Named).Obj()
case varTag: case varTag:
pos := p.pos() pos := p.pos()
pkg, name := p.qualifiedName() pkg, name := p.qualifiedName()
typ := p.typ(nil) typ := p.typ(nil)
p.declare(types.NewVar(pos, pkg, name, typ)) obj = types.NewVar(pos, pkg, name, typ)
p.declare(obj)
case funcTag: case funcTag:
pos := p.pos() pos := p.pos()
...@@ -245,11 +256,16 @@ func (p *importer) obj(tag int) { ...@@ -245,11 +256,16 @@ func (p *importer) obj(tag int) {
params, isddd := p.paramList() params, isddd := p.paramList()
result, _ := p.paramList() result, _ := p.paramList()
sig := types.NewSignature(nil, params, result, isddd) sig := types.NewSignature(nil, params, result, isddd)
p.declare(types.NewFunc(pos, pkg, name, sig)) obj = types.NewFunc(pos, pkg, name, sig)
p.declare(obj)
default: default:
errorf("unexpected object tag %d", tag) errorf("unexpected object tag %d", tag)
} }
if aliasName != "" {
p.declare(types.NewAlias(aliasPos, p.pkgList[0], aliasName, 0, obj))
}
} }
func (p *importer) pos() token.Pos { func (p *importer) pos() token.Pos {
...@@ -845,7 +861,11 @@ const ( ...@@ -845,7 +861,11 @@ const (
fractionTag // not used by gc fractionTag // not used by gc
complexTag complexTag
stringTag stringTag
nilTag // only used by gc (appears in exported inlined function bodies)
unknownTag // not used by gc (only appears in packages with errors) unknownTag // not used by gc (only appears in packages with errors)
// Aliases
aliasTag
) )
var predeclared = []types.Type{ var predeclared = []types.Type{
......
...@@ -9,6 +9,8 @@ package exports ...@@ -9,6 +9,8 @@ package exports
import ( import (
"go/ast" "go/ast"
"go/build"
"math"
) )
// Issue 3682: Correctly read dotted identifiers from export data. // Issue 3682: Correctly read dotted identifiers from export data.
...@@ -27,6 +29,10 @@ const ( ...@@ -27,6 +29,10 @@ const (
C7 = `bar\n` C7 = `bar\n`
) )
const (
C8 => math.Pi
)
type ( type (
T1 int T1 int
T2 [10]int T2 [10]int
...@@ -75,9 +81,19 @@ type ( ...@@ -75,9 +81,19 @@ type (
T28 func(T28) T28 T28 func(T28) T28
) )
type (
T29 => ast.File
T30 => build.Context
)
var ( var (
V0 int V0 int
V1 = -991.0 V1 = -991.0
V2 float32 = 1.2
)
var (
V3 => build.Default
) )
func F1() {} func F1() {}
...@@ -87,3 +103,7 @@ func F4() float32 { return 0 } ...@@ -87,3 +103,7 @@ func F4() float32 { return 0 }
func F5(a, b, c int, u, v, w struct{ x, y T1 }, more ...interface{}) (p, q, r chan<- T10) func F5(a, b, c int, u, v, w struct{ x, y T1 }, more ...interface{}) (p, q, r chan<- T10)
func (p *T1) M1() func (p *T1) M1()
func F6 => math.Sin
func F7 => ast.IsExported
func F8 => build.Import
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment