Imported Upstream version 4.8.1
[platform/upstream/gcc48.git] / gcc / testsuite / go.test / test / interface / private.go
1 // $G $D/${F}1.go && errchk $G $D/$F.go
2
3 // NOTE: This test is not run by 'run.go' and so not run by all.bash.
4 // To run this test you must use the ./run shell script.
5
6 // Copyright 2011 The Go Authors. All rights reserved.
7 // Use of this source code is governed by a BSD-style
8 // license that can be found in the LICENSE file.
9
10 // Test that unexported methods are not visible outside the package.
11 // Does not compile.
12
13 package main
14
15 import "./private1"
16
17 type Exported interface {
18         private()
19 }
20
21 type Implementation struct{}
22
23 func (p *Implementation) private() {}
24
25 func main() {
26         var x Exported
27         x = new(Implementation)
28         x.private()
29
30         var px p.Exported
31         px = p.X
32
33         px.private()                    // ERROR "private"
34
35         px = new(Implementation)        // ERROR "private"
36
37         x = px                          // ERROR "private"
38 }