[dev.typealias] cmd/compile, go/types, go/importer: various alias related fixes

cmd/compile:
- remove crud from prior alias implementation
- better comments in places

go/types:
- fix TypeName.IsAlias predicate
- more tests

go/importer (go/internal/gcimporter15):
- handle "@" format for anonymous fields using aliases
  (currently tested indirectly via x/tools/gcimporter15 tests)

For #18130.

Change-Id: I23a6d4e3a4c2a5c1ae589513da73fde7cad5f386
Reviewed-on: https://go-review.googlesource.com/35101
Reviewed-by: Alan Donovan <adonovan@google.com>
This commit is contained in:
Robert Griesemer 2016-12-27 16:53:33 -08:00
parent 49de5f0351
commit f011e0c6c3
5 changed files with 53 additions and 72 deletions

View file

@ -447,30 +447,6 @@ func unidealType(typ *Type, val Val) *Type {
}
func (p *exporter) obj(sym *Sym) {
if sym.Flags&SymAlias != 0 {
p.tag(aliasTag)
p.pos(nil) // TODO(gri) fix position information
// Aliases can only be exported from the package that
// declares them (aliases to aliases are resolved to the
// original object, and so are uses of aliases in inlined
// exported function bodies). Thus, we only need the alias
// name without package qualification.
if sym.Pkg != localpkg {
Fatalf("exporter: export of non-local alias: %v", sym)
}
p.string(sym.Name)
orig := sym.Def.Sym
if orig.Flags&SymAlias != 0 {
Fatalf("exporter: original object %v marked as alias", sym)
}
p.qualifiedName(orig)
return
}
if sym != sym.Def.Sym {
Fatalf("exporter: exported object %v is not original %v", sym, sym.Def.Sym)
}
// Exported objects may be from different packages because they
// may be re-exported via an exported alias or as dependencies in
// exported inlined function bodies. Thus, exported object names
@ -885,15 +861,15 @@ func (p *exporter) fieldName(t *Field) {
name := t.Sym.Name
if t.Embedded != 0 {
// anonymous field - we distinguish between 3 cases:
// 1) field name matches base type name and name is exported
// 2) field name matches base type name and name is not exported
// 3) field name doesn't match base type name (type name is alias)
// 1) field name matches base type name and is exported
// 2) field name matches base type name and is not exported
// 3) field name doesn't match base type name (alias name)
bname := basetypeName(t.Type)
if name == bname {
if exportname(name) {
name = "" // 1) we don't need to know the name
name = "" // 1) we don't need to know the field name or package
} else {
name = "?" // 2) use unexported name to force package export
name = "?" // 2) use unexported name "?" to force package export
}
} else {
// 3) indicate alias and export name as is
@ -920,11 +896,10 @@ func basetypeName(t *Type) string {
if s == nil && t.IsPtr() {
s = t.Elem().Sym // deref
}
// s should exist, but be conservative
if s != nil {
return s.Name
}
return ""
return "" // unnamed type
}
func (p *exporter) paramList(params *Type, numbered bool) {