diff --git a/lang/types/type.go b/lang/types/type.go index 9461b1f9..aa72ca86 100644 --- a/lang/types/type.go +++ b/lang/types/type.go @@ -550,8 +550,12 @@ func NewType(s string) *Type { 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 { + if obj == nil { + panic("malformed type") + } switch obj.Kind { case KindBool: return NewBool() diff --git a/lang/types/value.go b/lang/types/value.go index 9281d974..1edd23e9 100644 --- a/lang/types/value.go +++ b/lang/types/value.go @@ -774,6 +774,7 @@ func NewList(t *Type) *ListValue { return nil // sanity check } return &ListValue{ + V: []Value{}, T: t, } }