add method Value() Value to InterfaceValue.
use Value() in print to print underlying value
from interface.
before:
package main
import "fmt"
func main() {
x := []interface{} {1, "hello", 2.5};
fmt.Println(x[0], x[1], x[2], x);
}
1 hello 2.5 [<non-nil interface> <non-nil interface> <non-nil interface>]
after:
1 hello 2.5 [1 hello 2.5]
R=r
DELTA=44 (22 added, 16 deleted, 6 changed)
OCL=27139
CL=27141
diff --git a/src/lib/fmt/print.go b/src/lib/fmt/print.go
index ca5bec9..5fd230f 100644
--- a/src/lib/fmt/print.go
+++ b/src/lib/fmt/print.go
@@ -451,12 +451,11 @@
}
p.add('}');
case reflect.InterfaceKind:
- inter := field.(reflect.InterfaceValue).Get();
- if inter == nil {
+ value := field.(reflect.InterfaceValue).Value();
+ if value == nil {
s = "<nil>"
} else {
- // should never happen since a non-nil interface always has a type
- s = "<non-nil interface>";
+ return p.printField(value);
}
default:
s = "?" + field.Type().String() + "?";