-
Notifications
You must be signed in to change notification settings - Fork 164
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
spec: is dict[k] an error if k is unhashable? #65
Comments
alandonovan
changed the title
spec: is dict[key] an error if k is unhashable?
spec: is dict[k] an error if k is unhashable?
Jul 4, 2019
See also google/starlark-go#113 and google/starlark-go#165 |
bazel-io
pushed a commit
to bazelbuild/bazel
that referenced
this issue
Jul 11, 2019
Related: bazelbuild/starlark#65, #8730 Closes #8837. PiperOrigin-RevId: 257578468
irengrig
pushed a commit
to irengrig/bazel
that referenced
this issue
Jul 15, 2019
Related: bazelbuild/starlark#65, bazelbuild#8730 Closes bazelbuild#8837. PiperOrigin-RevId: 257578468
More weirdness: are functions hashable or not?
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The Go implementation of Starlark, following Python2 and 3, rejects a dictionary operation in which the key is unhashable:
By contrast, the Java implementation permits a lookup with any value, including unhashable ones. The lookup fails, though it is not necessarily an error, so execution may continue:
(This behavior occurs even when the dict is non-empty, so it can't be explained as the implementation taking a shortcut for empty dicts.)
Clearly, the Java implementation is in fact hashing the key, so the error message ("unhashable type") issued by an update operation such as
{}.update([([], 1)])
seems not to tell the whole story.I think the spec should state that all dict operations attempt to hash the key (even when unnecessary, such as {}.get(k)) and fail if the key is unhashable.
The text was updated successfully, but these errors were encountered: