Fix issues with nested dicts#2253
Conversation
|
Cases fixed from lpython import i32
def test_nested_dict():
d: dict[i32, dict[i32, i32]] = {1: {2: 3}}
d[1] = {} # Segmentation Fault
test_nested_dict()from lpython import i32
def test_nested_dict():
d: dict[i32, dict[i32, i32]] = {1: {2: 3}}
d[1][4] = 5 # KeyError
test_nested_dict()from lpython import i32
def test_nested_dict():
d: dict[i32, dict[i32, i32]] = {}
d[1] = {}
assert len(d) == 1
assert len(d[1]) == 0
d[1][2] = 3 # FP Exception (!?)
test_nested_dict()from lpython import i32
def test_nested_dict():
d: dict[i32, dict[i32, i32]] = {1: {2: 3}}
assert len(d) == 1
assert len(d[1]) == 1
d[1][3] = 4 # vs here KeyError
test_nested_dict()Some tests from lpython import i32
def test_nested_dict():
d: dict[i32, dict[i32, i32]] = {1001: {2002: 3003}}
dx: dict[i32, i32]
d[1001][2003] = 4005
dx = d[1001]
print(dx.keys())
test_nested_dict()from lpython import i32
def test_nested_dict():
d: dict[i32, dict[i32, dict[i32, i32]]] = {1001: {2002: {3003: 4004}}}
dx: dict[i32, i32]
d[1001][2002][4005] = 5006
dx = d[1001][2002]
print(dx.keys())
test_nested_dict()def test_nested_dict():
d: dict[i32, dict[i32, dict[i32, list[i32]]]] = {1001: {2002: {3003: [4004]}}}
dx: dict[i32, list[i32]]
d[1001][2002][4005] = [4004, 5006]
dx = d[1001][2002]
print(dx.keys(), dx[3003], dx[4005])
test_nested_dict() |
|
Now, issue in from lpython import i32
def test_nested_dict():
d: dict[i32, dict[i32, i32]] = {1001: {2002: 3003}, 1002: {1: 2}}
d[1001] = d[1002]
d[1001][2003] = 4005
test_nested_dict()def test_nested_dict():
d: dict[i32, dict[i32, i32]] = {1001: {2002: 3003}, 1002: {101: 2}}
# d[1001] = {10: 20}
d[1001] = d[1002]
d[1001][100] = 4005
# issue is only in this combination... (hangs)
# d[1001][100] works if not d[1001] = d[1002]
# and with d[1001] = d[1002], d[1001][101] works (key already +nt in d[1002])
test_nested_dict() |
21289fe to
3da0e4f
Compare
|
Tried figuring out the issue. This issue is confirmed by these from lpython import i32
def test_nested_dict():
d: dict[i32, dict[i32, i32]] = {1001: {2002: 3003}, 1002: {101: 2}}
print(len(d[1001]), len(d[1002])) # 1, 1
d[1001] = d[1002]
print(len(d[1001]), len(d[1002])) # 0, 1
test_nested_dict() |
|
Fixed above issue by calling
An issue popped up with |
dictsdicts
|
Thanks, great work. @czgdp1807 can you please review it? |
|
Currently we do not support operations like l: list[list[i32]] = [[1, 2, 3], [4, 5, 6]]
l[1].append(7) # semantic error: Only Name type and constant integers supported in CallThis should be done in This fix is important to ensure correct benchmarking of the changes in this PR. |
czgdp1807
left a comment
There was a problem hiding this comment.
So far it looks good to me.
How? This PR is related to |
I used lists to just illustrate that the issue is not restricted to this PR - it is for anything that uses subscripts. For example, this analogous code does not work d: dict[i32, dict[i32, i32]] = {1: {2: 3}, 4: {5: 6}}
d[1].pop(2) # same issue |
|
Got it. Let’s fix it in a subsequent PR. |
Fixes issues to enable use of nested dictionaries.