Closed milas closed 3 years ago
https://pkg.go.dev/go.starlark.net/starlark says:
Starlark's None value is not equal to Go's nil. Go's nil is not a legal Starlark value,
but the compiler will not stop you from converting nil to Value.
Be careful to avoid allowing Go nil values to leak into Starlark data structures.
Constructing a Tuple containing nil values is a mistake. It should not be the job of FromKeywords to spot it. Even if it did split "shallow" nils, it could not spot nils that lie deeper in the data structure.
Either omit the name and value from the tuple, or pass None explicitly.
Unfortunate, but understandable! Thanks for the quick response 👍
Expected Behavior
When creating a
starlarkstruct.Struct
from Go code usingFromKeywords
orFromStringDict
, if a value isnil
, it should be treated asNone
.Example:
I'd expect that I could use this as a normal struct, and the
key
field would have a value ofNone
.Actual Behavior
This will panic on
Freeze()
(due to trying to recursively freeze entries) and if you try to accesskey
, you'll get an error:Other notes
This came up along with #347 because we're creating some
starlarkstruct
s with (possiblyNone
) embeddedstarlarkstruct
s.I think this could be a pretty straightforward change to ensure that
entry
is always constructed with the provided value if non-nil, otherwise,starlark.None
. I'm happy to open a PR along with that change + expanded test case if you agree with that approach.