core: Fix crashes on invalid subscripting & iterating over non-iterables. #440

Open
lyken wants to merge 2 commits from fix-panic-432 into master
Collaborator

Fixes the crash seen in #432. This PR fixes the following two specific issues.

1. Crash on attempting to subscript into an non-scriptable value.

For example:

def run() -> int32:
    value = 123

    value[:1] = 456 # nac3core crashes here

    index = 5
    value[index] = 456 # nac3core crashes here
    # SIDENOTE: For this particular crash to happen in nac3core, the subscript
    # cannot be a constant - if we were to type `value[5] = "hello"`, it
    # wouldn't crash, and a different error would be thrown (gracefully)
    # in nac3core.

Now a proper error is reported:

1 error(s) occurred during top level analysis.
=========== ERROR 1/1 ============
'int32' object is not subscriptable at src/test_crash.py:X:Y
==================================

Furthermore, the crash on #432 is now also fixed, and a proper error message is reported:

'artiq.coredevice.shuttler.DCBias' object is not subscriptable at /home/lyken/artiq/artiq/frontend/artiq_sinara_tester.py:879:16

2. Crash on attempting to use for to iterate over an non-iterable value.

For example:

def run() -> int32:
    for i in 123: # nac3core crashes here
        pass

Now a proper error is reported:

1 error(s) occurred during top level analysis.
=========== ERROR 1/1 ============
'int32' object is not iterable at src/test_crash.py:X:Y
==================================
Fixes the crash seen in https://git.m-labs.hk/M-Labs/nac3/issues/432. This PR fixes the following two specific issues. ### 1. Crash on attempting to subscript into an non-scriptable value. For example: ```python def run() -> int32: value = 123 value[:1] = 456 # nac3core crashes here index = 5 value[index] = 456 # nac3core crashes here # SIDENOTE: For this particular crash to happen in nac3core, the subscript # cannot be a constant - if we were to type `value[5] = "hello"`, it # wouldn't crash, and a different error would be thrown (gracefully) # in nac3core. ``` Now a proper error is reported: ``` 1 error(s) occurred during top level analysis. =========== ERROR 1/1 ============ 'int32' object is not subscriptable at src/test_crash.py:X:Y ================================== ``` Furthermore, the crash on https://git.m-labs.hk/M-Labs/nac3/issues/432 is now also fixed, and a proper error message is reported: ``` 'artiq.coredevice.shuttler.DCBias' object is not subscriptable at /home/lyken/artiq/artiq/frontend/artiq_sinara_tester.py:879:16 ``` ### 2. Crash on attempting to use `for` to iterate over an non-iterable value. For example: ```python def run() -> int32: for i in 123: # nac3core crashes here pass ``` Now a proper error is reported: ``` 1 error(s) occurred during top level analysis. =========== ERROR 1/1 ============ 'int32' object is not iterable at src/test_crash.py:X:Y ================================== ```
lyken added 2 commits 2024-06-27 17:06:35 +08:00
lyken requested review from derppening 2024-06-27 17:06:39 +08:00
lyken added a new dependency 2024-06-27 17:13:12 +08:00
lyken force-pushed fix-panic-432 from 2acf9b88e9 to 56fa2b6803 2024-06-28 15:46:00 +08:00 Compare
This pull request can be merged automatically.
You are not authorized to merge this pull request.
You can also view command line instructions.

Step 1:

From your project repository, check out a new branch and test the changes.
git checkout -b fix-panic-432 master
git pull origin fix-panic-432

Step 2:

Merge the changes and update on Gitea.
git checkout master
git merge --no-ff fix-panic-432
git push origin master
Sign in to join this conversation.
No reviewers
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Reference: M-Labs/nac3#440
No description provided.