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) {
}
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 {
case constTag:
pos := p.pos()
pkg, name := p.qualifiedName()
typ := p.typ(nil)
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:
_ = p.typ(nil)
obj = p.typ(nil).(*types.Named).Obj()
case varTag:
pos := p.pos()
pkg, name := p.qualifiedName()
typ := p.typ(nil)
p.declare(types.NewVar(pos, pkg, name, typ))
obj = types.NewVar(pos, pkg, name, typ)
p.declare(obj)
case funcTag:
pos := p.pos()
......@@ -245,11 +256,16 @@ func (p *importer) obj(tag int) {
params, isddd := p.paramList()
result, _ := p.paramList()
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:
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 {
......@@ -845,7 +861,11 @@ const (
fractionTag // not used by gc
complexTag
stringTag
nilTag // only used by gc (appears in exported inlined function bodies)
unknownTag // not used by gc (only appears in packages with errors)
// Aliases
aliasTag
)
var predeclared = []types.Type{
......
......@@ -9,6 +9,8 @@ package exports
import (
"go/ast"
"go/build"
"math"
)
// Issue 3682: Correctly read dotted identifiers from export data.
......@@ -27,6 +29,10 @@ const (
C7 = `bar\n`
)
const (
C8 => math.Pi
)
type (
T1 int
T2 [10]int
......@@ -75,9 +81,19 @@ type (
T28 func(T28) T28
)
type (
T29 => ast.File
T30 => build.Context
)
var (
V0 int
V1 = -991.0
V1 = -991.0
V2 float32 = 1.2
)
var (
V3 => build.Default
)
func F1() {}
......@@ -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 (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