You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Request better error message for dict and set #2042
The error message is accurate, but could be more helpful:
/Users/brian/CLionProjects/lpython/src/bin/python /Users/brian/CLionProjects/lpython/lasr/LP-pycharm/issue2034.py
semantic error: All Set values must be of the same typefor now
--> /Users/brian/CLionProjects/lpython/lasr/LP-pycharm/issue2034.py:15:7 - 16:28
|
15 | foo = {'ttype' , ttype,
| ^^^^^^^^^^^^^^^^^^^...
...
|
16 |'contents', contents}
| ...^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LPython probably knows that the right-hand side should be a dict, so it might be better if LPython told me of a type mismatch between the left-hand and right-hand sides, that the right-hand side should be a dict and not a set. Instead, it tells me that my set is wrong. That's correct, of course, but it leads me in the wrong direction. If LPython allowed heterogeneous sets, it wouldn't even report that error!
Here, the value (in the assignment statement) is visited first and ASR is constructed for that. That's why, the set members are checked for type match. After constructing the value ASR LPython visits the target.
Here is another example that throws the error you were expecting:
I'm not sure if it is possible to show some kind of hint only for the Dict and Set assignment. So, that it would be easy for the user to debug the code. I need to investigate this.
I think this issue would get fixed when we support error recovery mechanism. With the error recovery, I think LPython would/can print two errors as follows:
semantic error: All Set values must be of the same type for now |15 | foo = {'ttype' , ttype, | ^^^^^^^^^^^^^^^^^^^...... |16 | 'contents', contents}semantic error: Type mismatch in assignment, the types must be compatible --> examples/expr2.py:36:5 |36 | foo = {'ttype', 'ttype', | ^^^ type mismatch ('dict[str, FullFormValue]' and 'set[str]') |36 | foo = {'ttype', 'ttype', | ^^^^^^^^^^^^^^^^^^...... |37 | 'contents', 'contents'} | ...^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch ('dict[str, FullFormValue]' and 'set[str]')
Activity
Thirumalai-Shaktivel commentedon Jun 27, 2023
Here, the value (in the assignment statement) is visited first and ASR is constructed for that. That's why, the
setmembers are checked for type match. After constructing the value ASR LPython visits the target.Here is another example that throws the error you were expecting:
Thirumalai-Shaktivel commentedon Jun 27, 2023
I'm not sure if it is possible to show some kind of hint only for the Dict and Set assignment. So, that it would be easy for the user to debug the code. I need to investigate this.
Fixed Issue lcompilers#2042
Fixed issue lcompilers#2042 - dispatched the type of list and dict
ubaidsk commentedon Mar 6, 2024
I think this issue would get fixed when we support error recovery mechanism. With the error recovery, I think LPython would/can print two errors as follows:
Fixed Issue lcompilers#2042
Fixed issue lcompilers#2042 - dispatched the type of list and dict
Fixed Issue lcompilers#2042
Fixed issue lcompilers#2042 - dispatched the type of list and dict
Fixed Issue lcompilers#2042
Fixed issue lcompilers#2042 - dispatched the type of list and dict
Fixed Issue lcompilers#2042
Fixed issue lcompilers#2042 - dispatched the type of list and dict
8 remaining items
Fixed issue lcompilers#2042 - dispatched the type of list and dict
Fixed issue lcompilers#2042 - dispatched the type of list and dict
Fixed Issue lcompilers#2042
Fixed issue lcompilers#2042 - dispatched the type of list and dict
Fixed Issue lcompilers#2042
Fixed issue lcompilers#2042 - dispatched the type of list and dict
Fixed Issue lcompilers#2042
Fixed issue lcompilers#2042 - dispatched the type of list and dict
Fixed Issue lcompilers#2042
Fixed issue lcompilers#2042 - dispatched the type of list and dict
Fixed issue lcompilers#2042 - dispatched the type of list and dict
Fixed Issue lcompilers#2042
Fixed issue lcompilers#2042 - dispatched the type of list and dict
Fixed issue lcompilers#2042 - dispatched the type of list and dict
Function Default Arguments (#2618)