| 
									
										
										
										
											2008-09-11 17:19:38 -07:00
										 |  |  | // $G $D/$F.go && $L $F.$A && ./$A.out || echo BUG should not crash | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // 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 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Interface | 
					
						
							| 
									
										
										
										
											2009-01-20 14:40:40 -08:00
										 |  |  | type I interface { F() int } | 
					
						
							| 
									
										
										
										
											2008-09-11 17:19:38 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  | // Implements interface | 
					
						
							| 
									
										
										
										
											2009-01-20 14:40:40 -08:00
										 |  |  | type S struct { } | 
					
						
							| 
									
										
										
										
											2008-09-11 17:19:38 -07:00
										 |  |  | func (s *S) F() int { return 1 } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Allocates S but returns I | 
					
						
							|  |  |  | // Arg is unused but important: | 
					
						
							|  |  |  | // if you take it out (and the 0s below) | 
					
						
							|  |  |  | // then the bug goes away. | 
					
						
							| 
									
										
										
										
											2009-01-20 14:40:40 -08:00
										 |  |  | func NewI(i int) I { | 
					
						
							| 
									
										
										
										
											2009-01-06 15:19:02 -08:00
										 |  |  | 	return new(S) | 
					
						
							| 
									
										
										
										
											2008-09-11 17:19:38 -07:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Uses interface method. | 
					
						
							| 
									
										
										
										
											2009-01-20 14:40:40 -08:00
										 |  |  | func Use(x I) { | 
					
						
							| 
									
										
										
										
											2008-09-11 17:19:38 -07:00
										 |  |  | 	x.F() | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | func main() { | 
					
						
							|  |  |  | 	i := NewI(0); | 
					
						
							|  |  |  | 	Use(i); | 
					
						
							| 
									
										
										
										
											2008-09-29 13:16:22 -07:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-09-11 17:19:38 -07:00
										 |  |  | 	// Again, without temporary | 
					
						
							|  |  |  | 	// Crashes because x.F is 0. | 
					
						
							|  |  |  | 	Use(NewI(0)); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 |