lcompilers / lpython

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

Numpy arrays should not allow out of bounds access in case of IndexError #2531

Open faze-geek opened 7 months ago

faze-geek commented 7 months ago
from numpy import int32
from enum import Enum

class ArraySizes(Enum):
    SIZE_3: i32 = 3
    SIZE_10: i32 = 10

def f(xi32: i32[:]) -> i32:
    xi32[0] = 1
    xi32[1] = 2
    xi32[2] = 3
    xi32[3] = 4
    print(xi32)
    print(xi32[3])

def d():
    ai32: i32[ArraySizes.SIZE_3] = empty(ArraySizes.SIZE_3.value, dtype=int32)
    f(ai32)

d()

(lp) C:\Users\kunni\lpython>src\bin\lpython try.py
1 2 3
4
faze-geek commented 7 months ago

Similarly for other creation methods like using empty().