blob: 17244360e0b9774cbe1138cc31ec559f1507474d [file] [log] [blame]
Peter Collingbournead9841e2014-11-27 00:06:42 +00001// RUN: llgo -o %t %s
2// RUN: %t 2>&1 | FileCheck %s
3
4// CHECK: !!!! 123
5// CHECK-NEXT: errno 123
6
7package main
8
9var errors = [...]string{}
10
11func itoa(val int) string { // do it here rather than with fmt to avoid dependency
12 if val < 0 {
13 return "-" + itoa(-val)
14 }
15 var buf [32]byte // big enough for int64
16 i := len(buf) - 1
17 for val >= 10 {
18 buf[i] = byte(val%10 + '0')
19 i--
20 val /= 10
21 }
22 buf[i] = byte(val + '0')
23 return string(buf[i:])
24}
25
26type Errno uintptr
27
28func (e Errno) Error() string {
29 println("!!!!", uintptr(e))
30 if 0 <= int(e) && int(e) < len(errors) {
31 s := errors[e]
32 if s != "" {
33 return s
34 }
35 }
36 return "errno " + itoa(int(e))
37}
38
39func main() {
40 e := Errno(123)
41 i := (interface{})(e)
42 println(i.(error).Error())
43}