2008-06-06 14:27:34 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// $G $D/$F.go && $L $F.$A && ./$A.out
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								// 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.
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								package main
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-12-10 12:53:23 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								type S struct {
							 | 
						
					
						
							
								
									
										
										
										
											2008-06-06 14:27:34 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									a,b	int;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-12-10 12:53:23 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								type I1 interface {
							 | 
						
					
						
							
								
									
										
										
										
											2008-06-06 14:27:34 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									f	()int;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-12-10 12:53:23 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								type I2 interface {
							 | 
						
					
						
							
								
									
										
										
										
											2009-09-28 14:05:34 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									g() int;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									f() int;
							 | 
						
					
						
							
								
									
										
										
										
											2008-06-06 14:27:34 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-12-10 12:53:23 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								func (this *S) f()int {
							 | 
						
					
						
							
								
									
										
										
										
											2008-06-06 14:27:34 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									return this.a;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-12-10 12:53:23 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								func (this *S) g()int {
							 | 
						
					
						
							
								
									
										
										
										
											2008-06-06 14:27:34 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									return this.b;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								func
							 | 
						
					
						
							
								
									
										
										
										
											2009-12-10 12:53:23 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
								main() {
							 | 
						
					
						
							
								
									
										
										
										
											2008-06-06 14:27:34 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									var i1 I1;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									var i2 I2;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									var g *S;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-01-06 15:19:02 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									s := new(S);
							 | 
						
					
						
							
								
									
										
										
										
											2008-06-06 14:27:34 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
									s.a = 5;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									s.b = 6;
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									// call structure
							 | 
						
					
						
							
								
									
										
										
										
											2008-08-11 22:07:49 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									if s.f() != 5 { panic(11); }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									if s.g() != 6 { panic(12); }
							 | 
						
					
						
							
								
									
										
										
										
											2008-06-06 14:27:34 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									i1 = s;		// convert S to I1
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-11 17:55:16 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									i2 = i1.(I2);	// convert I1 to I2
							 | 
						
					
						
							
								
									
										
										
										
											2008-06-06 14:27:34 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									// call interface
							 | 
						
					
						
							
								
									
										
										
										
											2008-08-11 22:07:49 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									if i1.f() != 5 { panic(21); }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									if i2.f() != 5 { panic(22); }
							 | 
						
					
						
							| 
								
							 | 
							
								
							 | 
							
								
							 | 
							
							
									if i2.g() != 6 { panic(23); }
							 | 
						
					
						
							
								
									
										
										
										
											2008-06-06 14:27:34 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-11 17:55:16 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									g = i1.(*S);		// convert I1 to S
							 | 
						
					
						
							
								
									
										
										
										
											2008-08-11 22:07:49 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									if g != s { panic(31); }
							 | 
						
					
						
							
								
									
										
										
										
											2008-06-06 14:27:34 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								
							 | 
						
					
						
							
								
									
										
										
										
											2009-02-11 17:55:16 -08:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									g = i2.(*S);		// convert I2 to S
							 | 
						
					
						
							
								
									
										
										
										
											2008-08-11 22:07:49 -07:00
										 
									 
								 
							 | 
							
								
									
										
									
								
							 | 
							
								
							 | 
							
							
									if g != s { panic(32); }
							 | 
						
					
						
							
								
									
										
										
										
											2008-06-06 14:27:34 -07:00
										 
									 
								 
							 | 
							
								
							 | 
							
								
							 | 
							
							
								}
							 |