diff --git a/src/lpython/semantics/python_ast_to_asr.cpp b/src/lpython/semantics/python_ast_to_asr.cpp index 947d870e98..b5e8c153d8 100644 --- a/src/lpython/semantics/python_ast_to_asr.cpp +++ b/src/lpython/semantics/python_ast_to_asr.cpp @@ -2735,7 +2735,7 @@ class CommonVisitor : public AST::BaseVisitor { throw SemanticAbort(); } if (ASR::is_a(*asr_alloc_type)) { - ASR::symbol_t *sym = ASR::down_cast(asr_alloc_type)->m_derived_type; + ASR::symbol_t *sym = ASRUtils::symbol_get_past_external(ASR::down_cast(asr_alloc_type)->m_derived_type); if (ASR::is_a(*sym)) { ASR::StructType_t *st = ASR::down_cast(sym); if (st->m_abi != ASR::abiType::BindC) { diff --git a/tests/errors/bindc_10e.py b/tests/errors/bindc_10e.py index bdbff7df6c..f8d9ca5c4b 100644 --- a/tests/errors/bindc_10e.py +++ b/tests/errors/bindc_10e.py @@ -1,5 +1,5 @@ -from lpython import (i64, i16, CPtr, c_p_pointer, Pointer, sizeof, packed, - dataclass, ccallable, ccall, i32) +from lpython import i64, i16, CPtr, c_p_pointer, Pointer, sizeof, ccall, i32 +from bindc_10e_mod import S @ccall def _lfortran_malloc(size: i32) -> CPtr: @@ -9,14 +9,6 @@ def _lfortran_malloc(size: i32) -> CPtr: def alloc(buf_size:i64) -> CPtr: return _lfortran_malloc(i32(buf_size)) - -@packed -@dataclass -class S: - a: i16 - b: i64 - - def main(): p1: CPtr = alloc(sizeof(S)) print(p1) diff --git a/tests/errors/bindc_10e_mod.py b/tests/errors/bindc_10e_mod.py new file mode 100644 index 0000000000..1b0f48e086 --- /dev/null +++ b/tests/errors/bindc_10e_mod.py @@ -0,0 +1,7 @@ +from lpython import packed, dataclass, i16, i64 + +@packed +@dataclass +class S: + a: i16 + b: i64 diff --git a/tests/reference/asr-bindc_10e-8b10394.json b/tests/reference/asr-bindc_10e-8b10394.json index 9fdf2f9acd..38439231b2 100644 --- a/tests/reference/asr-bindc_10e-8b10394.json +++ b/tests/reference/asr-bindc_10e-8b10394.json @@ -2,12 +2,12 @@ "basename": "asr-bindc_10e-8b10394", "cmd": "lpython --show-asr --no-color {infile} -o {outfile}", "infile": "tests/errors/bindc_10e.py", - "infile_hash": "36d1b5d366716d6a601db544fe8ff32aba76518181e71a98a4e6500c", + "infile_hash": "fa023d4ad17e426f778a99326998e6dbeac5428fa252974a39a3219d", "outfile": null, "outfile_hash": null, "stdout": null, "stdout_hash": null, "stderr": "asr-bindc_10e-8b10394.stderr", - "stderr_hash": "7686dd8c9b718548d301e28d39cd15a85b00030172c5658b38a75af5", + "stderr_hash": "9ea4ff2c8a8789057456196deb5772e4b3a2dffadbd10ecfe5f15f29", "returncode": 2 } \ No newline at end of file diff --git a/tests/reference/asr-bindc_10e-8b10394.stderr b/tests/reference/asr-bindc_10e-8b10394.stderr index 3639b97f68..cc7c1cd0aa 100644 --- a/tests/reference/asr-bindc_10e-8b10394.stderr +++ b/tests/reference/asr-bindc_10e-8b10394.stderr @@ -1,12 +1,14 @@ semantic error: The struct in c_p_pointer must be C interoperable - --> tests/errors/bindc_10e.py:23:38 + --> tests/errors/bindc_10e.py:15:38 | -23 | p2: Pointer[S] = c_p_pointer(p1, S) +15 | p2: Pointer[S] = c_p_pointer(p1, S) | ^ not C interoperable + + --> tests/errors/bindc_10e_mod.py:5:1 - 7:10 | -15 | class S: + 5 | class S: | ~~~~~~~~... ... | -17 | b: i64 + 7 | b: i64 | ...~~~~~~~~~~ help: add the @ccallable decorator to this struct to make it C interoperable