lang: types: Improve docs for New and initialize the list
If we use this to generate a zero value, we want to make sure it's completely initialized in case we use it subsequently. We also improve the docs at the same time.
This commit is contained in:
@@ -550,8 +550,12 @@ func NewType(s string) *Type {
|
|||||||
return nil // error (this also matches the empty string as input)
|
return nil // error (this also matches the empty string as input)
|
||||||
}
|
}
|
||||||
|
|
||||||
// New creates a new Value of this type.
|
// New creates a new Value of this type. It will represent the "zero" value. It
|
||||||
|
// panics if you give it a malformed type.
|
||||||
func (obj *Type) New() Value {
|
func (obj *Type) New() Value {
|
||||||
|
if obj == nil {
|
||||||
|
panic("malformed type")
|
||||||
|
}
|
||||||
switch obj.Kind {
|
switch obj.Kind {
|
||||||
case KindBool:
|
case KindBool:
|
||||||
return NewBool()
|
return NewBool()
|
||||||
|
|||||||
@@ -774,6 +774,7 @@ func NewList(t *Type) *ListValue {
|
|||||||
return nil // sanity check
|
return nil // sanity check
|
||||||
}
|
}
|
||||||
return &ListValue{
|
return &ListValue{
|
||||||
|
V: []Value{},
|
||||||
T: t,
|
T: t,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user