lcompilers / lpython

Python compiler
https://lpython.org/
Other
1.5k stars 158 forks source link

Error Message (Dict,Set,List ) Type Mismatch #2577

Closed assem2002 closed 5 months ago

assem2002 commented 7 months ago

Fixes #2042

The Fix

Screen Shot Of The Code In The Issue Description After Fix. Screenshot from 2024-03-06 20-07-53

The issue we're facing could be described as "CONSTRUCTION WHILE ASSIGNING" problem. It happens when _visitassign function is invoked. It could happen with annassign function also as shown below

Mention To Some Other Cases

The issue appears in the following code:

someVar : list[i32]
someVar = {1 ,"whatever"}

Screenshot from 2024-03-06 20-12-29

And also here:

@dataclass
class FullFormValue:
    list_i32 : list[i32]
    string   : str

ttype    : str = FullFormValue(DEAD_LIST, 1)
contents : FullFormValue = FullFormValue([1, 2], '')

**Let me know if the object construction handling is a concern and needs to be debugged in some other way.

Simplifying the code

kmr-srbh commented 7 months ago

Please replace "Fix Issue #2042" with "Fixes #2042" so that the PR gets linked to the issue.

assem2002 commented 7 months ago

I Edited it, #Thanks @kmr-srbh

Thirumalai-Shaktivel commented 7 months ago

Please mark this PR ready for review once it is ready.

assem2002 commented 7 months ago

@Thirumalai-Shaktivel

The problem we face in issue #2042 appears to be more complex.

@Shaikh-Ubaid suggested an error recovery mechanism to be implemented in the system to handle such multiple errors while doing ASR construction.

Probably we should make a bigger issue with specified tasks as long as there's no such mechanism or similar ones already implemented.

I'll draft the PR,but I think the issue should be closed unless a hard-coded fix is fine for now.

Shaikh-Ubaid commented 5 months ago

The fix in this PR doesn't seem to be a high priority. I think we should fix it issue by adding support for error-recovery (as mentioned in https://github.com/lcompilers/lpython/issues/2042#issuecomment-1981703862), which in itself is a larger issue. Should we tackle this later @certik?

certik commented 5 months ago

Yes, correct. We have to extend the ASR->ASR transformation to just report all errors and recover from them. We should not be catching exceptions like that. In fact ideally we should not use exceptions at all. I think we should be able to recover on the level of statements, and then have special handling in blocks of statements (functions).

In terms of priorities, first we should deliver beta quality ASR and LLVM (via LFortran) for compiling valid code. Only then focus on beautiful error messages for invalid code.