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

Merged
sb10q merged 1 commits from fix-panic-432 into master 2024-08-17 17:37:21 +08:00
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 1 commit 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
sb10q merged commit 56fa2b6803 into master 2024-07-02 18:23:02 +08:00
sb10q deleted branch fix-panic-432 2024-07-02 18:23:04 +08:00
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.