}
func (p *P) printField(field reflect.Value) (was_string bool) {
- if stringer, ok := field.Interface().(String); ok {
- p.addstr(stringer.String());
- return false; // this value is not a string
+ inter := field.Interface();
+ if inter != nil {
+ if stringer, ok := inter.(String); ok {
+ p.addstr(stringer.String());
+ return false; // this value is not a string
+ }
}
s := "";
switch field.Kind() {
p.add('{');
p.doprint(field, true, false);
p.add('}');
+ case reflect.InterfaceKind:
+ inter := field.(reflect.InterfaceValue).Get();
+ if inter == nil {
+ s = "<nil>"
+ } else {
+ // should never happen since a non-nil interface always has a type
+ s = "<non-nil interface>";
+ }
default:
s = "?" + field.Type().String() + "?";
}
}
field := getField(v, fieldnum);
fieldnum++;
- if c != 'T' { // don't want thing to describe itself if we're asking for its type
- if formatter, ok := field.Interface().(Format); ok {
+ inter := field.Interface();
+ if inter != nil && c != 'T' { // don't want thing to describe itself if we're asking for its type
+ if formatter, ok := inter.(Format); ok {
formatter.Format(p, c);
continue;
}
return len(t.field)
}
+var NilInterface = NewInterfaceTypeStruct("nil", "", new([]Field, 0));
+
// -- Func
export type FuncType interface {
}
export func ParseTypeString(name, typestring string) Type {
+ if typestring == "" {
+ // If the typestring is empty, it represents (the type of) a nil interface value
+ return NilInterface
+ }
p := new(Parser);
p.str = typestring;
p.Next();
export type MissingValue interface {
Kind() int;
Type() Type;
+ Addr() Addr;
}
type MissingValueStruct struct {
}
func MissingCreator(typ Type, addr Addr) Value {
- return &MissingValueStruct{ Common{IntKind, typ, addr} }
+ return &MissingValueStruct{ Common{MissingKind, typ, addr} }
}
// -- Int