]> Cypherpunks.ru repositories - gostls13.git/blob - test/alias2.go
cmd/compile/internal/gc: enable new parser by default
[gostls13.git] / test / alias2.go
1 // errorcheck
2
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.
6
7 // Test basic restrictions on alias declarations.
8
9 package p
10
11 import (
12         "fmt" // use at most once (to test "imported but not used" error)
13         "go/build"
14         . "go/build"
15         "io"
16         "math"
17         "unsafe"
18 )
19
20 // helper
21 var before struct {
22         f
23 }
24
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"
28
29 type _ => _ // ERROR "_ is not a package-qualified identifier"
30 type t => _ // ERROR "_ is not a package-qualified identifier"
31
32 const _ => iota // ERROR "iota is not a package-qualified identifier"
33 type _ => int   // ERROR "int is not a package-qualified identifier"
34
35 const c => iota // ERROR "iota is not a package-qualified identifier"
36 type t => int   // ERROR "int is not a package-qualified identifier"
37
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"
41
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"
47
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"
52
53 // TODO(gri) fix error printing - should not print a qualified identifier...
54 var _ => Default.ARCH // ERROR "build.Default is not a package"
55
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"
59
60 // aliases must refer to entities of the same kind
61 const _ => math.Pi
62 const pi => math.Pi
63 const pi1 => math.Sin // ERROR "math.Sin is not a constant"
64
65 type _ => io.Writer
66 type writer => io.Writer
67 type writer1 => math.Sin // ERROR "math.Sin is not a type"
68
69 var _ => build.Default
70 var def => build.Default
71 var def1 => build.Import // ERROR "build.Import is not a variable"
72
73 func _ => math.Sin
74 func sin => math.Sin
75 func sin1 => math.Pi // ERROR "math.Pi is not a function"
76
77 // alias reference to a package marks package as used
78 func _ => fmt.Println
79
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"
85
86 // type aliases denote identical types
87 type myPackage => build.Package
88
89 var pkg myPackage
90 var _ build.Package = pkg   // valid assignment
91 var _ *build.Package = &pkg // valid assignment
92
93 // helper
94 type after struct{}
95
96 func (after) m() {}