← 输入框|github.com|刷新
Skip to content

Bug: Catch unhashable objects in dict and set at the ASR level #2663

Closed

Description

@kmr-srbh

In the current state, we throw an error stating that hashing a specific type is not implemented. This happens totally in the back-end when we try to hash the object.

from lpython import i32

my_dict: dict[list[i32], str] = {[1, 2]: "first", [3, 4]: "second"}
(lp) saurabh-kumar@Awadh:~/Projects/System/lpython$ ./src/bin/lpython ./examples/example.py
Internal Compiler Error: Unhandled exception
Traceback (most recent call last):
.
.
.
    llvm::Value* key_hash = get_key_hash(current_capacity, key, key_asr_type, *module);
LCompilersException: Hashing list[i32] isn't implemented yet.

However, we do not catch types which cannot be hashed. All mutable types are incompatible to become a key in a dict and element in a set. We should detect them early at the ASR level and throw an error.

Activity

  1. changed the title [-]Bug: Catch unhashable `dict` key types at the ASR level[/-] [+]Bug: Catch unhashable object types at the ASR level for `dict` and `set`[/+] on Apr 25, 2024
  2. changed the title [-]Bug: Catch unhashable object types at the ASR level for `dict` and `set`[/-] [+]Bug: Catch unhashable objects in `dict` and `set` at the ASR level[/+] on Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions