Skip to content

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

Closed
@kmr-srbh

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.

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