1
0
mirror of https://github.com/golang/go synced 2024-11-18 09:24:54 -07:00
go/test/fixedbugs/bug099.go

38 lines
637 B
Go
Raw Normal View History

// run
// 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 }
// Implements interface
2009-01-20 15:40:40 -07:00
type S struct { }
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)
}
// Uses interface method.
2009-01-20 15:40:40 -07:00
func Use(x I) {
x.F()
}
func main() {
i := NewI(0);
Use(i);
// Again, without temporary
// Crashes because x.F is 0.
Use(NewI(0));
}