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.
12 "fmt" // use at most once (to test "imported but not used" error)
25 // aliases must refer to package-qualified identifiers
26 // TODO(gri) should only see one error for declaration below - fix this
27 const _ => 0 // ERROR "unexpected literal 0|_ is not a package-qualified identifier"
29 type _ => _ // ERROR "_ is not a package-qualified identifier"
30 type t => _ // ERROR "_ is not a package-qualified identifier"
32 const _ => iota // ERROR "iota is not a package-qualified identifier"
33 type _ => int // ERROR "int is not a package-qualified identifier"
35 const c => iota // ERROR "iota is not a package-qualified identifier"
36 type t => int // ERROR "int is not a package-qualified identifier"
38 // dot-imported identifiers are not qualified identifiers
39 // TODO(gri) fix error printing - should not print a qualified identifier...
40 var _ => Default // ERROR "build\.Default is not a package-qualified identifier"
42 // qualified identifiers must start with a package
43 var _ => before.f // ERROR "before is not a package"
44 func _ => before.f // ERROR "before is not a package"
45 var _ => after.m // ERROR "after is not a package"
46 func _ => after.m // ERROR "after is not a package"
48 var v => before.f // ERROR "before is not a package"
49 func f => before.f // ERROR "before is not a package"
50 var v => after.m // ERROR "after is not a package"
51 func f => after.m // ERROR "after is not a package"
53 // TODO(gri) fix error printing - should not print a qualified identifier...
54 var _ => Default.ARCH // ERROR "build.Default is not a package"
56 // aliases may not refer to package unsafe
57 type ptr => unsafe.Pointer // ERROR "ptr refers to package unsafe"
58 func size => unsafe.Sizeof // ERROR "size refers to package unsafe"
60 // aliases must refer to entities of the same kind
63 const pi1 => math.Sin // ERROR "math.Sin is not a constant"
66 type writer => io.Writer
67 type writer1 => math.Sin // ERROR "math.Sin is not a type"
69 var _ => build.Default
70 var def => build.Default
71 var def1 => build.Import // ERROR "build.Import is not a variable"
75 func sin1 => math.Pi // ERROR "math.Pi is not a function"
77 // alias reference to a package marks package as used
80 // TODO(gri) aliased cannot be exported yet - fix this
81 const Pi => math.Pi // ERROR "cannot export alias Pi"
82 type Writer => io.Writer // ERROR "cannot export alias Writer"
83 var Def => build.Default // ERROR "cannot export alias Def"
84 func Sin => math.Sin // ERROR "cannot export alias Sin"
86 // type aliases denote identical types
87 type myPackage => build.Package
90 var _ build.Package = pkg // valid assignment
91 var _ *build.Package = &pkg // valid assignment