[ILibraryView] don't fail on nested dangling ref

This commit is contained in:
Jan Petykiewicz 2026-03-30 23:34:31 -07:00
commit d03fafcaf6
2 changed files with 21 additions and 2 deletions

View file

@ -294,8 +294,9 @@ class ILibraryView(Mapping[str, 'Pattern'], metaclass=ABCMeta):
def flatten_single(name: str) -> None:
flattened[name] = None
pat = self[name].deepcopy()
refs_by_target = tuple((target, tuple(refs)) for target, refs in pat.refs.items())
for target in pat.refs:
for target, refs in refs_by_target:
if target is None:
continue
if dangling_ok and target not in self:
@ -310,7 +311,7 @@ class ILibraryView(Mapping[str, 'Pattern'], metaclass=ABCMeta):
if target_pat.is_empty() and not ports_only: # avoid some extra allocations
continue
for ref in pat.refs[target]:
for ref in refs:
if flatten_ports and ref.repetition is not None and target_pat.ports:
raise PatternError(
f'Cannot flatten ports from repeated ref to {target!r}; '