3 // Copyright 2016 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
7 // Test basic restrictions on alias declarations.
13 "fmt" // use at most once (to test "imported but not used" error)
26 // aliases must refer to package-qualified identifiers
27 // TODO(gri) should only see one error for declaration below - fix this
28 const _ => 0 // ERROR "unexpected literal 0|_ is not a package-qualified identifier"
30 type _ => _ // ERROR "_ is not a package-qualified identifier"
31 type t => _ // ERROR "_ is not a package-qualified identifier"
33 const _ => iota // ERROR "iota is not a package-qualified identifier"
34 type _ => int // ERROR "int is not a package-qualified identifier"
36 const c => iota // ERROR "iota is not a package-qualified identifier"
37 type t => int // ERROR "int is not a package-qualified identifier"
39 // dot-imported identifiers are not qualified identifiers
40 // TODO(gri) fix error printing - should not print a qualified identifier...
41 var _ => Default // ERROR "build\.Default is not a package-qualified identifier"
43 // qualified identifiers must start with a package
44 var _ => before.f // ERROR "before is not a package"
45 func _ => before.f // ERROR "before is not a package"
46 var _ => after.m // ERROR "after is not a package"
47 func _ => after.m // ERROR "after is not a package"
49 var v => before.f // ERROR "before is not a package"
50 func f => before.f // ERROR "before is not a package"
51 var v => after.m // ERROR "after is not a package"
52 func f => after.m // ERROR "after is not a package"
54 // TODO(gri) fix error printing - should print correct qualified identifier...
55 var _ => Default.ARCH // ERROR "build.Default is not a package"
57 // aliases may not refer to package unsafe
58 type ptr => unsafe.Pointer // ERROR "ptr refers to package unsafe"
59 func size => unsafe.Sizeof // ERROR "size refers to package unsafe"
61 // aliases must refer to entities of the same kind
64 const pi1 => math.Sin // ERROR "math.Sin is not a constant"
67 type writer => io.Writer
68 type writer1 => math.Sin // ERROR "math.Sin is not a type"
70 var _ => build.Default
71 var def => build.Default
72 var def1 => build.Import // ERROR "build.Import is not a variable"
76 func sin1 => math.Pi // ERROR "math.Pi is not a function"
78 // aliases may not be called init
79 func init => flag.Parse // ERROR "cannot declare init"
81 // alias reference to a package marks package as used
84 // re-exported aliases
87 type Writer => io.Writer
89 var Def => build.Default
93 // type aliases denote identical types
94 type myPackage => build.Package
97 var _ build.Package = pkg // valid assignment
98 var _ *build.Package = &pkg // valid assignment