-
Notifications
You must be signed in to change notification settings - Fork 171
Detect unhashable object types at the ASR level #2664
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
04d8739
Detect unhashable types for `dict` key
kmr-srbh 87d6177
Tests: Add error tests and update references
kmr-srbh 1202bba
Create a function to check for hashable objects
kmr-srbh be293b3
Tests: Add error tests for `set` and update references
kmr-srbh f9a8ebe
Tests: Update error tests and references
kmr-srbh 020cf55
Check for unhashable types in type-annotations
kmr-srbh 53341f3
Tests: Update tests and references
kmr-srbh e79637a
Fix indentation
kmr-srbh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from lpython import i32 | ||
|
||
def test_dict_key1(): | ||
my_dict: dict[list[i32], str] = {[1, 2]: "first", [3, 4]: "second"} | ||
|
||
test_dict_key1() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from lpython import i32 | ||
|
||
def test_dict_key2(): | ||
my_dict: dict[dict[i32, str], str] = {{1: "a", 2: "b"}: "first", {3: "c", 4: "d"}: "second"} | ||
|
||
test_dict_key2() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from lpython import i32 | ||
|
||
def test_dict_key3(): | ||
my_dict: dict[set[str], str] = {{1, 2}: "first", {3, 4}: "second"} | ||
|
||
test_dict_key3() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
def test_dict_key4(): | ||
print({[1, 2]: "first", [3, 4]: "second"}) | ||
|
||
test_dict_key4() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
def test_dict_key5(): | ||
print({{1: "a", 2: "b"}: "first", {3: "c", 4: "d"}: "second"}) | ||
|
||
test_dict_key5() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
def test_dict_key6(): | ||
print({{1, 2}: "first", {3, 4}: "second"}) | ||
|
||
test_dict_key6() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from lpython import i32 | ||
|
||
def test_set_object1(): | ||
my_set: set[list[i32]] = {[1, 2], [3, 4]} | ||
|
||
test_set_object1() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from lpython import i32 | ||
|
||
def test_set_object2(): | ||
my_set: set[dict[i32, str]] = {{1: "a", 2: "b"}, {3: "c", 4: "d"}} | ||
|
||
test_set_object2() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from lpython import i32 | ||
|
||
def test_set_object3(): | ||
my_set: set[set[i32]] = {{1, 2}, {3, 4}} | ||
|
||
test_set_object3() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
def test_set_object4(): | ||
print({[1, 2], [3, 4]}) | ||
|
||
test_set_object4() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
def test_set_object5(): | ||
print({{1: "a", 2: "b"}, {3: "c", 4: "d"}}) | ||
|
||
test_set_object5() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
def test_set_object6(): | ||
print({{1, 2}, {3, 4}}) | ||
|
||
test_set_object6() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"basename": "asr-test_dict_key1-6e57a28", | ||
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}", | ||
"infile": "tests/errors/test_dict_key1.py", | ||
"infile_hash": "0ee4ab5e47edab5de323d7cf97cf3e726e54882e4a5fadb82ee9aedc", | ||
"outfile": null, | ||
"outfile_hash": null, | ||
"stdout": null, | ||
"stdout_hash": null, | ||
"stderr": "asr-test_dict_key1-6e57a28.stderr", | ||
"stderr_hash": "4ee828a6b9a93bfb8285c2006843243b5327f915f9548a2f1b3f1480", | ||
"returncode": 2 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
semantic error: Unhashable type: 'list' | ||
--> tests/errors/test_dict_key1.py:4:19 | ||
| | ||
4 | my_dict: dict[list[i32], str] = {[1, 2]: "first", [3, 4]: "second"} | ||
| ^^^^^^^^^ Mutable type 'list' cannot become a key in dict. Hint: Use an immutable type for key. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"basename": "asr-test_dict_key2-18ea6fb", | ||
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}", | ||
"infile": "tests/errors/test_dict_key2.py", | ||
"infile_hash": "25b325264991082018c989f990a6b71409e7af0df4a27e5b5142a349", | ||
"outfile": null, | ||
"outfile_hash": null, | ||
"stdout": null, | ||
"stdout_hash": null, | ||
"stderr": "asr-test_dict_key2-18ea6fb.stderr", | ||
"stderr_hash": "5883683aaf0a4ae56b5fd86f56f6900e3e752a72bc675af9c607d998", | ||
"returncode": 2 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
semantic error: Unhashable type: 'dict' | ||
--> tests/errors/test_dict_key2.py:4:19 | ||
| | ||
4 | my_dict: dict[dict[i32, str], str] = {{1: "a", 2: "b"}: "first", {3: "c", 4: "d"}: "second"} | ||
| ^^^^^^^^^^^^^^ Mutable type 'dict' cannot become a key in dict. Hint: Use an immutable type for key. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"basename": "asr-test_dict_key3-9fc7793", | ||
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}", | ||
"infile": "tests/errors/test_dict_key3.py", | ||
"infile_hash": "9675711d37ed0e58ddd82a53ec580cc21c58a9b94ad598b706fb78f8", | ||
"outfile": null, | ||
"outfile_hash": null, | ||
"stdout": null, | ||
"stdout_hash": null, | ||
"stderr": "asr-test_dict_key3-9fc7793.stderr", | ||
"stderr_hash": "bd995f8512a83892aa1be985c6f7ff1761691829150549ba4ac84f17", | ||
"returncode": 2 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
semantic error: Unhashable type: 'set' | ||
--> tests/errors/test_dict_key3.py:4:19 | ||
| | ||
4 | my_dict: dict[set[str], str] = {{1, 2}: "first", {3, 4}: "second"} | ||
| ^^^^^^^^ Mutable type 'set' cannot become a key in dict. Hint: Use an immutable type for key. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"basename": "asr-test_dict_key4-dc7abfc", | ||
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}", | ||
"infile": "tests/errors/test_dict_key4.py", | ||
"infile_hash": "197ac00a9a0a5763f939d8b5aec2e33a5b3ec769d93149a1c93999c1", | ||
"outfile": null, | ||
"outfile_hash": null, | ||
"stdout": null, | ||
"stdout_hash": null, | ||
"stderr": "asr-test_dict_key4-dc7abfc.stderr", | ||
"stderr_hash": "ff55c824acc6a3bc2c7f8845b345bcf5d66d13374526ab958a005dc7", | ||
"returncode": 2 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
semantic error: Unhashable type: 'list' | ||
--> tests/errors/test_dict_key4.py:2:12 | ||
| | ||
2 | print({[1, 2]: "first", [3, 4]: "second"}) | ||
| ^^^^^^ Mutable type 'list' cannot become a key in dict. Hint: Use an immutable type for key. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"basename": "asr-test_dict_key5-87496d1", | ||
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}", | ||
"infile": "tests/errors/test_dict_key5.py", | ||
"infile_hash": "08a7118a664a5ac63f470b5a47d19ed7c35a06e3c8ae40a7b44010ea", | ||
"outfile": null, | ||
"outfile_hash": null, | ||
"stdout": null, | ||
"stdout_hash": null, | ||
"stderr": "asr-test_dict_key5-87496d1.stderr", | ||
"stderr_hash": "c7ae39bf80d3a6d1817fbd7aba5455e96623b1225abeb9428af2c73a", | ||
"returncode": 2 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
semantic error: Unhashable type: 'dict' | ||
--> tests/errors/test_dict_key5.py:2:12 | ||
| | ||
2 | print({{1: "a", 2: "b"}: "first", {3: "c", 4: "d"}: "second"}) | ||
| ^^^^^^^^^^^^^^^^ Mutable type 'dict' cannot become a key in dict. Hint: Use an immutable type for key. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"basename": "asr-test_dict_key6-1d334b2", | ||
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}", | ||
"infile": "tests/errors/test_dict_key6.py", | ||
"infile_hash": "14ea00618e1414afe9f93d0aa0d4fd5b4332883465126cbba6faab76", | ||
"outfile": null, | ||
"outfile_hash": null, | ||
"stdout": null, | ||
"stdout_hash": null, | ||
"stderr": "asr-test_dict_key6-1d334b2.stderr", | ||
"stderr_hash": "74a8ee0549333b4659afc7deec824a14bbc672316b22e3c99a026846", | ||
"returncode": 2 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
semantic error: Unhashable type: 'set' | ||
--> tests/errors/test_dict_key6.py:2:12 | ||
| | ||
2 | print({{1, 2}: "first", {3, 4}: "second"}) | ||
| ^^^^^^ Mutable type 'set' cannot become a key in dict. Hint: Use an immutable type for key. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"basename": "asr-test_set_object1-d9bd2e1", | ||
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}", | ||
"infile": "tests/errors/test_set_object1.py", | ||
"infile_hash": "9450d7ca46f30271944800137d28413648bafdbeb7f0a7ac0906c832", | ||
"outfile": null, | ||
"outfile_hash": null, | ||
"stdout": null, | ||
"stdout_hash": null, | ||
"stderr": "asr-test_set_object1-d9bd2e1.stderr", | ||
"stderr_hash": "b528f86f591ab403348d8dd5037d2385fdb7ce29501215a69d10702f", | ||
"returncode": 2 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
semantic error: Unhashable type: 'list' | ||
--> tests/errors/test_set_object1.py:4:17 | ||
| | ||
4 | my_set: set[list[i32]] = {[1, 2], [3, 4]} | ||
| ^^^^^^^^^ Mutable type 'list' cannot be stored in a set. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"basename": "asr-test_set_object2-41401ff", | ||
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}", | ||
"infile": "tests/errors/test_set_object2.py", | ||
"infile_hash": "e7360eff7caf0991c5bd4c505a947d23e2bc01277e9a2966362400df", | ||
"outfile": null, | ||
"outfile_hash": null, | ||
"stdout": null, | ||
"stdout_hash": null, | ||
"stderr": "asr-test_set_object2-41401ff.stderr", | ||
"stderr_hash": "4fe845a8f949fce5b955b86d5a5ad60f0e1ae84e3c17b01572d37e2a", | ||
"returncode": 2 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
semantic error: Unhashable type: 'dict' | ||
--> tests/errors/test_set_object2.py:4:17 | ||
| | ||
4 | my_set: set[dict[i32, str]] = {{1: "a", 2: "b"}, {3: "c", 4: "d"}} | ||
| ^^^^^^^^^^^^^^ Mutable type 'dict' cannot be stored in a set. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"basename": "asr-test_set_object3-680b593", | ||
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}", | ||
"infile": "tests/errors/test_set_object3.py", | ||
"infile_hash": "f1dea0a951aa880721aa38a0dcf254983e7d50ab408c64c87b9a078e", | ||
"outfile": null, | ||
"outfile_hash": null, | ||
"stdout": null, | ||
"stdout_hash": null, | ||
"stderr": "asr-test_set_object3-680b593.stderr", | ||
"stderr_hash": "05d3a6338fd929fef485c7403500a1f2111dc8e638a3369ff942bea2", | ||
"returncode": 2 | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
semantic error: Unhashable type: 'set' | ||
--> tests/errors/test_set_object3.py:4:17 | ||
| | ||
4 | my_set: set[set[i32]] = {{1, 2}, {3, 4}} | ||
| ^^^^^^^^ Mutable type 'set' cannot be stored in a set. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"basename": "asr-test_set_object4-243eb04", | ||
"cmd": "lpython --show-asr --no-color {infile} -o {outfile}", | ||
"infile": "tests/errors/test_set_object4.py", | ||
"infile_hash": "0b339aaa798fca7bd12920c583b0d60d70fe2f8afeb68a1811992f59", | ||
"outfile": null, | ||
"outfile_hash": null, | ||
"stdout": null, | ||
"stdout_hash": null, | ||
"stderr": "asr-test_set_object4-243eb04.stderr", | ||
"stderr_hash": "dff44d0e30f3fed351e8df2bc1875c3a9972db927a58400df456ec12", | ||
"returncode": 2 | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.