Skip to content

Commit 27c5c5c

Browse files
committed
Add error message for non C interoperable structs
1 parent 91de604 commit 27c5c5c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/lpython/semantics/python_ast_to_asr.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2734,6 +2734,21 @@ class CommonVisitor : public AST::BaseVisitor<Struct> {
27342734
);
27352735
throw SemanticAbort();
27362736
}
2737+
if (ASR::is_a<ASR::Struct_t>(*asr_alloc_type)) {
2738+
ASR::StructType_t *st = ASR::down_cast<ASR::StructType_t>(ASR::down_cast<ASR::Struct_t>(asr_alloc_type)->m_derived_type);
2739+
if (st->m_abi != ASR::abiType::BindC) {
2740+
diag.add(diag::Diagnostic(
2741+
"The struct in c_p_pointer must be C interoperable",
2742+
diag::Level::Error, diag::Stage::Semantic, {
2743+
diag::Label("not C interoperable",
2744+
{asr_alloc_type->base.loc}),
2745+
diag::Label("help: add the @ccallable decorator to this struct to make it C interoperable",
2746+
{st->base.base.loc}, false)
2747+
})
2748+
);
2749+
throw SemanticAbort();
2750+
}
2751+
}
27372752
fill_shape_and_lower_bound_for_CPtrToPointer();
27382753
return ASR::make_CPtrToPointer_t(al, loc, cptr, pptr, target_shape, lower_bounds);
27392754
}

0 commit comments

Comments
 (0)