1
0
mirror of https://github.com/golang/go synced 2024-11-11 23:50:22 -07:00

[dev.typealias] go/types: remove some more vestiges of prior alias implementation

For #18130.

Change-Id: Ibec8efd158d32746978242910dc71e5ed23e9d91
Reviewed-on: https://go-review.googlesource.com/35092
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:
Robert Griesemer 2016-12-22 09:48:43 -08:00
parent 80d8b69e95
commit c80748e389
2 changed files with 0 additions and 157 deletions

View File

@ -1295,155 +1295,3 @@ func f(x int) { y := x; print(y) }
} }
} }
} }
// Alias-related code. Keep for now.
/*
func TestAliases(t *testing.T) {
testenv.MustHaveGoBuild(t)
const src = `
package b
import (
"./testdata/alias"
a "./testdata/alias"
"math"
)
const (
c1 = alias.Pi1
c2 => a.Pi1
c3 => a.Pi2
c4 => math.Pi
)
var (
v1 => alias.Default
v2 => a.Default
v3 = f1
)
type (
t1 => alias.Context
t2 => a.Context
)
func f1 => alias.Sin
func f2 => a.Sin
func _() {
assert(c1 == alias.Pi1 && c2 == a.Pi1 && c3 == a.Pi2 && c4 == math.Pi)
assert(c2 == c2 && c2 == c3 && c3 == c4)
v1 = v2 // must be assignable
var _ *t1 = new(t2) // must be assignable
var _ t2 = alias.Default
f1(1) // must be callable
f2(1)
_ = alias.Sin(1)
_ = a.Sin(1)
}
`
if out := compile(t, "testdata", "alias.go"); out != "" {
defer os.Remove(out)
}
DefPredeclaredTestFuncs() // declare assert built-in for testing
mustTypecheck(t, "Aliases", src, nil)
}
func compile(t *testing.T, dirname, filename string) string {
cmd := exec.Command(testenv.GoToolPath(t), "tool", "compile", filename)
cmd.Dir = dirname
out, err := cmd.CombinedOutput()
if err != nil {
t.Logf("%s", out)
t.Fatalf("go tool compile %s failed: %s", filename, err)
}
// filename should end with ".go"
return filepath.Join(dirname, filename[:len(filename)-2]+"o")
}
func TestAliasDefUses(t *testing.T) {
testenv.MustHaveGoBuild(t)
const src = `
package p
import(
"go/build"
"go/types"
)
// Defs
const Invalid => types.Invalid
type Struct => types.Struct
var Default => build.Default
func Implements => types.Implements
// Uses
const _ = Invalid
var _ types.Struct = Struct{} // types must be identical
var _ build.Context = Default
var _ = Implements(nil, nil)
`
info := Info{
Defs: make(map[*ast.Ident]Object),
Uses: make(map[*ast.Ident]Object),
}
mustTypecheck(t, "TestAliasDefUses", src, &info)
// verify Defs
defs := map[string]string{
"Invalid": "types.Invalid",
"Struct": "types.Struct",
"Default": "build.Default",
"Implements": "types.Implements",
}
for ident, obj := range info.Defs {
if alias, ok := obj.(*Alias); ok {
if want := defs[ident.Name]; want != "" {
orig := alias.Orig()
if got := orig.Pkg().Name() + "." + orig.Name(); got != want {
t.Errorf("%v: got %v, want %v", ident, got, want)
}
delete(defs, ident.Name) // mark as found
} else {
t.Errorf("unexpected alias def of %v", ident)
}
}
}
if len(defs) != 0 {
t.Errorf("missing aliases: %v", defs)
}
// verify Uses
uses := map[string]string{
"Invalid": "types.Invalid",
"Struct": "types.Struct",
"Default": "build.Default",
"Implements": "types.Implements",
}
for ident, obj := range info.Uses {
if alias, ok := obj.(*Alias); ok {
if want := uses[ident.Name]; want != "" {
orig := alias.Orig()
if got := orig.Pkg().Name() + "." + orig.Name(); got != want {
t.Errorf("%v: got %v, want %v", ident, got, want)
}
delete(uses, ident.Name) // mark as found
} else {
t.Errorf("unexpected alias use of %v", ident)
}
}
}
if len(uses) != 0 {
t.Errorf("missing aliases: %v", defs)
}
}
*/

View File

@ -295,11 +295,6 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr) {
} }
check.recordUse(e.Sel, exp) check.recordUse(e.Sel, exp)
// avoid further errors if the imported object is an alias that's broken
if exp == nil {
goto Error
}
// Simplified version of the code for *ast.Idents: // Simplified version of the code for *ast.Idents:
// - imported objects are always fully initialized // - imported objects are always fully initialized
switch exp := exp.(type) { switch exp := exp.(type) {