feat: in MainPodBuilder track literal contains in dict_contains (#456)

The MainPodBuilder automatically adds contains statements for operations
that are created from entries.  But if the contains statement was
already added manually there will be duplicates.  We now track manually
added contains statements so that we don't generate duplicates when
adding statements from entries that use them.
This commit is contained in:
Eduard S. 2026-01-19 16:50:02 +01:00 committed by GitHub
parent 0fca00cc93
commit 1724e7b146
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -131,7 +131,6 @@ pub struct MainPodBuilder {
pub operations: Vec<Operation>, pub operations: Vec<Operation>,
pub public_statements: Vec<Statement>, pub public_statements: Vec<Statement>,
// Internal state // Internal state
// TODO: track contains ops with literals added explicitly as well.
dict_contains: Vec<(Value, Value)>, // (root, key) dict_contains: Vec<(Value, Value)>, // (root, key)
} }
@ -177,6 +176,19 @@ impl MainPodBuilder {
pub fn insert(&mut self, public: bool, st_op: (Statement, Operation)) -> Result<()> { pub fn insert(&mut self, public: bool, st_op: (Statement, Operation)) -> Result<()> {
// TODO: Do error handling instead of panic // TODO: Do error handling instead of panic
let (st, op) = st_op; let (st, op) = st_op;
// If we're adding a Contains statement with literal arguments (an Entry), track it in
// `dict_contains` to avoid adding it again via `Self::add_entries_contains`.
if let Statement::Contains(
ValueRef::Literal(dict),
ValueRef::Literal(key),
ValueRef::Literal(_),
) = &st
{
let root_key = (dict.clone(), key.clone());
self.dict_contains.push(root_key);
}
if public { if public {
self.public_statements.push(st.clone()); self.public_statements.push(st.clone());
} }