2008-09-11 18:19:38 -06: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 15:40:40 -07:00
|
|
|
type I interface { F() int }
|
2008-09-11 18:19:38 -06:00
|
|
|
|
|
|
|
// Implements interface
|
2009-01-20 15:40:40 -07:00
|
|
|
type S struct { }
|
2008-09-11 18:19:38 -06: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 15:40:40 -07:00
|
|
|
func NewI(i int) I {
|
2009-01-06 16:19:02 -07:00
|
|
|
return new(S)
|
2008-09-11 18:19:38 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Uses interface method.
|
2009-01-20 15:40:40 -07:00
|
|
|
func Use(x I) {
|
2008-09-11 18:19:38 -06:00
|
|
|
x.F()
|
|
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
i := NewI(0);
|
|
|
|
Use(i);
|
2008-09-29 14:16:22 -06:00
|
|
|
|
2008-09-11 18:19:38 -06:00
|
|
|
// Again, without temporary
|
|
|
|
// Crashes because x.F is 0.
|
|
|
|
Use(NewI(0));
|
|
|
|
}
|
|
|
|
|