gcc/testsuite/go.go-torture/execute/printnil.go
raw| 1 | // printnil checks that fmt correctly handles a nil pointer receiver |
| 2 | // for a value method at all optimization levels. |
| 3 | package main |
| 4 | |
| 5 | import "fmt" |
| 6 | |
| 7 | type MyType struct { |
| 8 | val int |
| 9 | } |
| 10 | |
| 11 | func (t MyType) String() string { |
| 12 | return "foobar" |
| 13 | } |
| 14 | |
| 15 | func main() { |
| 16 | if got := fmt.Sprintf("%s", (*MyType)(nil)); got != "<nil>" { |
| 17 | panic(got) |
| 18 | } |
| 19 | } |