modernc.org/gc@v1.0.1-0.20240304020402-f0dba7c97c2b/testdata/errchk/test/interface/private.dir/prog.go (about) 1 // Copyright 2011 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Test that unexported methods are not visible outside the package. 6 // Does not compile. 7 8 package main 9 10 import "./private1" 11 12 type Exported interface { 13 private() 14 } 15 16 type Implementation struct{} 17 18 func (p *Implementation) private() {} 19 20 func main() { 21 var x Exported 22 x = new(Implementation) 23 x.private() 24 25 var px p.Exported 26 px = p.X 27 28 px.private() // ERROR "private" 29 30 px = new(Implementation) // ERROR "private" 31 32 x = px // ERROR "private" 33 }