}
}
}
-
-// 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)
- }
-}
-*/