From c80748e3894b5623681fc5f1059ffdbd2cff6b7c Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Thu, 22 Dec 2016 09:48:43 -0800 Subject: [PATCH] [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 TryBot-Result: Gobot Gobot Reviewed-by: Alan Donovan --- src/go/types/api_test.go | 152 --------------------------------------- src/go/types/call.go | 5 -- 2 files changed, 157 deletions(-) diff --git a/src/go/types/api_test.go b/src/go/types/api_test.go index 1208eb8b3a1..92c6d75e704 100644 --- a/src/go/types/api_test.go +++ b/src/go/types/api_test.go @@ -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) - } -} -*/ diff --git a/src/go/types/call.go b/src/go/types/call.go index 194b1fea10d..7f5823c8295 100644 --- a/src/go/types/call.go +++ b/src/go/types/call.go @@ -295,11 +295,6 @@ func (check *Checker) selector(x *operand, e *ast.SelectorExpr) { } 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: // - imported objects are always fully initialized switch exp := exp.(type) {