diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index e709d60ef9..c918c9ae76 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -455,7 +455,7 @@ RUN(NAME structs_01 LABELS cpython llvm c) RUN(NAME structs_02 LABELS cpython llvm c) RUN(NAME structs_03 LABELS llvm c) RUN(NAME structs_04 LABELS cpython llvm c) -RUN(NAME structs_05 LABELS llvm c) +RUN(NAME structs_05 LABELS cpython llvm c) RUN(NAME structs_06 LABELS cpython llvm c) RUN(NAME structs_07 LABELS llvm c EXTRAFILES structs_07b.c) @@ -480,6 +480,7 @@ RUN(NAME structs_21 LABELS cpython llvm c) RUN(NAME structs_22 LABELS cpython llvm c) RUN(NAME structs_23 LABELS cpython llvm c) RUN(NAME structs_24 LABELS cpython llvm c) +RUN(NAME structs_25 LABELS cpython llvm c) RUN(NAME sizeof_01 LABELS llvm c EXTRAFILES sizeof_01b.c) RUN(NAME sizeof_02 LABELS cpython llvm c) diff --git a/integration_tests/structs_05.py b/integration_tests/structs_05.py index d738778109..b730a5387b 100644 --- a/integration_tests/structs_05.py +++ b/integration_tests/structs_05.py @@ -50,7 +50,6 @@ def update_2(s: A[:]): s[1].c = i8(3) def g(): - # TODO: Enable cpython in integration_tests. y: A[2] = empty([2], dtype=A) y[0] = A(1.1, 1, i64(1), f32(1.1), i16(1), i8(1), True) y[1] = A(2.2, 2, i64(2), f32(2.2), i16(2), i8(2), True) diff --git a/integration_tests/structs_25.py b/integration_tests/structs_25.py new file mode 100644 index 0000000000..4ed57ea564 --- /dev/null +++ b/integration_tests/structs_25.py @@ -0,0 +1,20 @@ +from lpython import i32, dataclass +from numpy import empty + +@dataclass +class Foo: + x: i32 + y: i32 + +def init(foos: Foo[:]) -> None: + foos[0] = Foo(5, 21) + +def main0() -> None: + foos: Foo[1] = empty(1, dtype=Foo) + init(foos) + print("foos[0].x =", foos[0].x) + + assert foos[0].x == 5 + assert foos[0].y == 21 + +main0() diff --git a/src/runtime/lpython/lpython.py b/src/runtime/lpython/lpython.py index 103ec16da5..9c9eb79ef5 100644 --- a/src/runtime/lpython/lpython.py +++ b/src/runtime/lpython/lpython.py @@ -44,6 +44,7 @@ def __call__(self, arg): return self._convert(arg) def dataclass(arg): + arg.__class_getitem__ = lambda self: None return py_dataclass(arg) def is_dataclass(obj): diff --git a/tests/reference/asr-structs_05-fa98307.json b/tests/reference/asr-structs_05-fa98307.json index f8694a70e6..bf409124dc 100644 --- a/tests/reference/asr-structs_05-fa98307.json +++ b/tests/reference/asr-structs_05-fa98307.json @@ -2,7 +2,7 @@ "basename": "asr-structs_05-fa98307", "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", "infile": "tests/../integration_tests/structs_05.py", - "infile_hash": "0ca482232f99c40614dc5b994fa8c9f4865fbe72f5a133b02914b5ad", + "infile_hash": "94d06fb2844e1060d5df5291c3ccc4bd0e2bc8a8a59651814f0c4f0e", "outfile": null, "outfile_hash": null, "stdout": "asr-structs_05-fa98307.stdout",