Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(3592)

Side by Side Diff: test/fixedbugs/bug324.dir/main.go

Issue 4442071: code review 4442071: gc: correct handling of unexported method names in embe... (Closed)
Patch Set: diff -r 79deef5a2706 https://go.googlecode.com/hg/ Created 13 years, 11 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « test/fixedbugs/bug324.go ('k') | test/fixedbugs/bug324.dir/p.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 The Go Authors. All rights reserved. 1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package main 5 package main
6 6
7 import ( 7 import (
8 "./p" 8 "./p"
9 ) 9 )
10 10
11 type Exported interface { 11 type Exported interface {
12 private() 12 private()
13 } 13 }
14 14
15 type Implementation struct{} 15 type Implementation struct{}
16 16
17 func (p *Implementation) private() { println("main.Implementation.private()") } 17 func (p *Implementation) private() {}
18 18
19 19
20 func main() { 20 func main() {
21 // nothing unusual here 21 // nothing unusual here
22 var x Exported 22 var x Exported
23 x = new(Implementation) 23 x = new(Implementation)
24 x.private() // main.Implementation.private() 24 x.private() // main.Implementation.private()
25 25
26 // same here - should be and is legal 26 // same here - should be and is legal
27 var px p.Exported 27 var px p.Exported
28 px = p.X 28 px = p.X
29 ········ 29 ········
30 // this assignment is correctly illegal: 30 // this assignment is correctly illegal:
31 // px.private undefined (cannot refer to unexported field or method private) 31 // px.private undefined (cannot refer to unexported field or method private)
32 // px.private() 32 // px.private()
33 33
34 // this assignment is correctly illegal: 34 // this assignment is correctly illegal:
35 // *Implementation does not implement p.Exported (missing p.private method) 35 // *Implementation does not implement p.Exported (missing p.private method)
36 // px = new(Implementation) 36 // px = new(Implementation)
37 37
38 // this assignment is correctly illegal: 38 // this assignment is correctly illegal:
39 // p.Exported does not implement Exported (missing private method) 39 // p.Exported does not implement Exported (missing private method)
40 // x = px 40 // x = px
41 41
42 // this assignment unexpectedly compiles and then executes 42 // this assignment unexpectedly compiles and then executes
43 defer func() {
44 recover()
45 }()
43 x = px.(Exported) 46 x = px.(Exported)
gri 2011/04/20 23:06:48 couldn't this be a compile-time failure?
47 ········
48 println("should not get this far")
44 49
45 // this is a legitimate call, but because of the previous assignment, 50 // this is a legitimate call, but because of the previous assignment,
46 // it invokes the method private in p! 51 // it invokes the method private in p!
47 x.private() // p.Implementation.private() 52 x.private() // p.Implementation.private()
48 } 53 }
OLDNEW
« no previous file with comments | « test/fixedbugs/bug324.go ('k') | test/fixedbugs/bug324.dir/p.go » ('j') | no next file with comments »

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b