[ILibraryView / Pattern] flatten() should raise PatternError if asked to preserve ports from a repeated ref

This commit is contained in:
Jan Petykiewicz 2026-03-30 21:17:33 -07:00
commit c32168dc64
4 changed files with 36 additions and 0 deletions

View file

@ -308,6 +308,11 @@ class ILibraryView(Mapping[str, 'Pattern'], metaclass=ABCMeta):
continue
for ref in pat.refs[target]:
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}; '
'flatten with flatten_ports=False or expand/rename the ports manually first.'
)
p = ref.as_pattern(pattern=target_pat)
if not flatten_ports:
p.ports.clear()