-
Notifications
You must be signed in to change notification settings - Fork 218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
correct set.union method #574
Conversation
The `union` function on `set` is inconsistent with the behaviour of `update` as it does not support multiple iterable positional arguments as is the case in the Bazel specification of the language. This PR will align `starlark-go` with the Bazel spec. Note that the `set.union` method no longer uses the `Union` function defined in `value.go` in order to avoid making a new `set` instance for each interable processed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well spotted! Thanks for the fix.
starlark/library.go
Outdated
defer iter.Done() | ||
return resultSet.InsertAll(iter) | ||
}(); err != nil { | ||
return nil, err |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should return nameErr, like set_update.
But instead let's factor the common code of set_update and set_union since they only differ by whether the destination is a clone:
func set_union(_ *Thread, b *Builtin, args Tuple, kwargs []Tuple) (Value, error) {
if len(kwargs) > 0 {
return nil, nameErr(b, "union does not accept keyword arguments")
}
res := b.Receiver().(*Set).clone()
if err := setUpdate(res, args); err != nil {
return nil, nameErr(b, err)
}
return res, nil
}
func set_update(_ *Thread, b *Builtin, args Tuple, kwargs []Tuple) (Value, error) {
if len(kwargs) > 0 {
return nil, nameErr(b, "update does not accept keyword arguments")
}
recv := b.Receiver().(*Set)
if err := setUpdate(res, args); err != nil {
return nil,nameErr(b, err)
}
return None, nil
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah true; I will do that...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've also factored-out the check for the kwargs
because the update
/ union
prefix can be added later albeit with an additional colon in the message. This seems OK to me; let me know what you think.
Fixes in PR from @adonovan.
function name change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks!
The
union
function onset
is inconsistent with the behaviour ofupdate
as it does not support multiple iterable positional arguments as is the case in the Bazel specification of the language. This PR will alignstarlark-go
with the Bazel spec.Note that the
set.union
method no longer uses theUnion
function defined invalue.go
in order to avoid making a newset
instance for each interable processed.