| 
									
										
										
										
											2009-01-15 10:15:34 -08:00
										 |  |  | // $G $D/$F.go && $L $F.$A && ./$A.out || echo BUG interface6 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Copyright 2009 The Go Authors. All rights reserved. | 
					
						
							|  |  |  | // Use of this source code is governed by a BSD-style | 
					
						
							|  |  |  | // license that can be found in the LICENSE file. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-12 16:09:47 -07:00
										 |  |  | // Interface values containing structures. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-15 10:15:34 -08:00
										 |  |  | package main | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-08 15:21:41 -07:00
										 |  |  | import "os" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-15 10:15:34 -08:00
										 |  |  | var fail int | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func check(b bool, msg string) { | 
					
						
							| 
									
										
										
										
											2009-08-17 13:30:22 -07:00
										 |  |  | 	if (!b) { | 
					
						
							|  |  |  | 		println("failure in", msg); | 
					
						
							|  |  |  | 		fail++; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-01-15 10:15:34 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-20 14:40:40 -08:00
										 |  |  | type I1 interface { Get() int; Put(int); } | 
					
						
							| 
									
										
										
										
											2009-01-15 10:15:34 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-20 14:40:40 -08:00
										 |  |  | type S1 struct { i int } | 
					
						
							| 
									
										
										
										
											2009-01-15 10:15:34 -08:00
										 |  |  | func (p S1) Get() int { return p.i } | 
					
						
							|  |  |  | func (p S1) Put(i int) { p.i = i } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func f1() { | 
					
						
							| 
									
										
										
										
											2009-08-17 13:30:22 -07:00
										 |  |  | 	s := S1{1}; | 
					
						
							|  |  |  | 	var i I1 = s; | 
					
						
							|  |  |  | 	i.Put(2); | 
					
						
							|  |  |  | 	check(i.Get() == 1, "f1 i"); | 
					
						
							|  |  |  | 	check(s.i == 1, "f1 s"); | 
					
						
							| 
									
										
										
										
											2009-01-15 10:15:34 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func f2() { | 
					
						
							| 
									
										
										
										
											2009-08-17 13:30:22 -07:00
										 |  |  | 	s := S1{1}; | 
					
						
							|  |  |  | 	var i I1 = &s; | 
					
						
							|  |  |  | 	i.Put(2); | 
					
						
							|  |  |  | 	check(i.Get() == 1, "f2 i"); | 
					
						
							|  |  |  | 	check(s.i == 1, "f2 s"); | 
					
						
							| 
									
										
										
										
											2009-01-15 10:15:34 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func f3() { | 
					
						
							| 
									
										
										
										
											2009-08-17 13:30:22 -07:00
										 |  |  | 	s := &S1{1}; | 
					
						
							|  |  |  | 	var i I1 = s; | 
					
						
							|  |  |  | 	i.Put(2); | 
					
						
							|  |  |  | 	check(i.Get() == 1, "f3 i"); | 
					
						
							|  |  |  | 	check(s.i == 1, "f3 s"); | 
					
						
							| 
									
										
										
										
											2009-01-15 10:15:34 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-20 14:40:40 -08:00
										 |  |  | type S2 struct { i int } | 
					
						
							| 
									
										
										
										
											2009-01-15 10:15:34 -08:00
										 |  |  | func (p *S2) Get() int { return p.i } | 
					
						
							|  |  |  | func (p *S2) Put(i int) { p.i = i } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-19 11:54:59 -07:00
										 |  |  | // Disallowed by restriction of values going to pointer receivers | 
					
						
							| 
									
										
										
										
											2009-03-11 16:06:17 -07:00
										 |  |  | // func f4() { | 
					
						
							| 
									
										
										
										
											2009-08-17 13:30:22 -07:00
										 |  |  | //	 s := S2{1}; | 
					
						
							|  |  |  | //	 var i I1 = s; | 
					
						
							|  |  |  | //	 i.Put(2); | 
					
						
							|  |  |  | //	 check(i.Get() == 2, "f4 i"); | 
					
						
							|  |  |  | //	 check(s.i == 1, "f4 s"); | 
					
						
							| 
									
										
										
										
											2009-03-11 16:06:17 -07:00
										 |  |  | // } | 
					
						
							| 
									
										
										
										
											2009-01-15 10:15:34 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | func f5() { | 
					
						
							| 
									
										
										
										
											2009-08-17 13:30:22 -07:00
										 |  |  | 	s := S2{1}; | 
					
						
							|  |  |  | 	var i I1 = &s; | 
					
						
							|  |  |  | 	i.Put(2); | 
					
						
							|  |  |  | 	check(i.Get() == 2, "f5 i"); | 
					
						
							|  |  |  | 	check(s.i == 2, "f5 s"); | 
					
						
							| 
									
										
										
										
											2009-01-15 10:15:34 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func f6() { | 
					
						
							| 
									
										
										
										
											2009-08-17 13:30:22 -07:00
										 |  |  | 	s := &S2{1}; | 
					
						
							|  |  |  | 	var i I1 = s; | 
					
						
							|  |  |  | 	i.Put(2); | 
					
						
							|  |  |  | 	check(i.Get() == 2, "f6 i"); | 
					
						
							|  |  |  | 	check(s.i == 2, "f6 s"); | 
					
						
							| 
									
										
										
										
											2009-01-15 10:15:34 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-20 14:40:40 -08:00
										 |  |  | type I2 interface { Get() int64; Put(int64); } | 
					
						
							| 
									
										
										
										
											2009-01-15 10:15:34 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-20 14:40:40 -08:00
										 |  |  | type S3 struct { i, j, k, l int64 } | 
					
						
							| 
									
										
										
										
											2009-01-15 10:15:34 -08:00
										 |  |  | func (p S3) Get() int64 { return p.l } | 
					
						
							|  |  |  | func (p S3) Put(i int64) { p.l = i } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func f7() { | 
					
						
							| 
									
										
										
										
											2009-08-17 13:30:22 -07:00
										 |  |  | 	s := S3{1, 2, 3, 4}; | 
					
						
							|  |  |  | 	var i I2 = s; | 
					
						
							|  |  |  | 	i.Put(5); | 
					
						
							|  |  |  | 	check(i.Get() == 4, "f7 i"); | 
					
						
							|  |  |  | 	check(s.l == 4, "f7 s"); | 
					
						
							| 
									
										
										
										
											2009-01-15 10:15:34 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func f8() { | 
					
						
							| 
									
										
										
										
											2009-08-17 13:30:22 -07:00
										 |  |  | 	s := S3{1, 2, 3, 4}; | 
					
						
							|  |  |  | 	var i I2 = &s; | 
					
						
							|  |  |  | 	i.Put(5); | 
					
						
							|  |  |  | 	check(i.Get() == 4, "f8 i"); | 
					
						
							|  |  |  | 	check(s.l == 4, "f8 s"); | 
					
						
							| 
									
										
										
										
											2009-01-15 10:15:34 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func f9() { | 
					
						
							| 
									
										
										
										
											2009-08-17 13:30:22 -07:00
										 |  |  | 	s := &S3{1, 2, 3, 4}; | 
					
						
							|  |  |  | 	var i I2 = s; | 
					
						
							|  |  |  | 	i.Put(5); | 
					
						
							|  |  |  | 	check(i.Get() == 4, "f9 i"); | 
					
						
							|  |  |  | 	check(s.l == 4, "f9 s"); | 
					
						
							| 
									
										
										
										
											2009-01-15 10:15:34 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-01-20 14:40:40 -08:00
										 |  |  | type S4 struct { i, j, k, l int64 } | 
					
						
							| 
									
										
										
										
											2009-01-15 10:15:34 -08:00
										 |  |  | func (p *S4) Get() int64 { return p.l } | 
					
						
							|  |  |  | func (p *S4) Put(i int64) { p.l = i } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-10-19 11:54:59 -07:00
										 |  |  | // Disallowed by restriction of values going to pointer receivers | 
					
						
							| 
									
										
										
										
											2009-03-11 16:06:17 -07:00
										 |  |  | // func f10() { | 
					
						
							| 
									
										
										
										
											2009-08-17 13:30:22 -07:00
										 |  |  | //	 s := S4{1, 2, 3, 4}; | 
					
						
							|  |  |  | //	 var i I2 = s; | 
					
						
							|  |  |  | //	 i.Put(5); | 
					
						
							|  |  |  | //	 check(i.Get() == 5, "f10 i"); | 
					
						
							|  |  |  | //	 check(s.l == 4, "f10 s"); | 
					
						
							| 
									
										
										
										
											2009-03-11 16:06:17 -07:00
										 |  |  | // } | 
					
						
							| 
									
										
										
										
											2009-01-15 10:15:34 -08:00
										 |  |  | 
 | 
					
						
							|  |  |  | func f11() { | 
					
						
							| 
									
										
										
										
											2009-08-17 13:30:22 -07:00
										 |  |  | 	s := S4{1, 2, 3, 4}; | 
					
						
							|  |  |  | 	var i I2 = &s; | 
					
						
							|  |  |  | 	i.Put(5); | 
					
						
							|  |  |  | 	check(i.Get() == 5, "f11 i"); | 
					
						
							|  |  |  | 	check(s.l == 5, "f11 s"); | 
					
						
							| 
									
										
										
										
											2009-01-15 10:15:34 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func f12() { | 
					
						
							| 
									
										
										
										
											2009-08-17 13:30:22 -07:00
										 |  |  | 	s := &S4{1, 2, 3, 4}; | 
					
						
							|  |  |  | 	var i I2 = s; | 
					
						
							|  |  |  | 	i.Put(5); | 
					
						
							|  |  |  | 	check(i.Get() == 5, "f12 i"); | 
					
						
							|  |  |  | 	check(s.l == 5, "f12 s"); | 
					
						
							| 
									
										
										
										
											2009-01-15 10:15:34 -08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func main() { | 
					
						
							| 
									
										
										
										
											2009-08-17 13:30:22 -07:00
										 |  |  | 	f1(); | 
					
						
							|  |  |  | 	f2(); | 
					
						
							|  |  |  | 	f3(); | 
					
						
							|  |  |  | //	f4(); | 
					
						
							|  |  |  | 	f5(); | 
					
						
							|  |  |  | 	f6(); | 
					
						
							|  |  |  | 	f7(); | 
					
						
							|  |  |  | 	f8(); | 
					
						
							|  |  |  | 	f9(); | 
					
						
							|  |  |  | //	f10(); | 
					
						
							|  |  |  | 	f11(); | 
					
						
							|  |  |  | 	f12(); | 
					
						
							|  |  |  | 	if fail > 0 { | 
					
						
							|  |  |  | 		os.Exit(1) | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2009-01-15 10:15:34 -08:00
										 |  |  | } |