Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow inner connects #369

Merged
merged 3 commits into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions edg/core/Blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def __init__(self, ref: ConstraintExpr, units: str):
self.ref = ref
self.units = units

def set_elt_proto(self, pb, ref_map):
def set_elt_proto(self, pb, ref_map=None):
new_phrase = pb.description.add()
new_phrase.param.path.CopyFrom(ref_map[self.ref])
new_phrase.param.unit = self.units
Expand Down Expand Up @@ -554,7 +554,10 @@ def connect(self, *connects: Union[BasePort, Connection], flatten=False) -> Conn
enclosing_block = port._block_parent()
assert enclosing_block is not None
if enclosing_block._parent is not self:
raise UnconnectableError("Inaccessible port for connection")
raise UnconnectableError("Inaccessible port: must be own port or inner block port")
if not(port._parent is enclosing_block or \
(isinstance(port._parent, Vector) and port._parent._parent is enclosing_block)):
raise UnconnectableError("Inaccessible port: cannot connect inner ports on inner blocks")
self._connects_by_port[port] = connect
connect.add_ports(connects_ports_new)

Expand Down
1 change: 0 additions & 1 deletion edg/core/test_bundle.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from typing import *
import unittest

from . import *
Expand Down
26 changes: 26 additions & 0 deletions edg/core/test_connect_bundle.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import unittest

from . import *
from .HdlUserExceptions import UnconnectableError
from .test_elaboration_common import TestBlockSource
from .test_bundle import TestBundle


class TestInner(Block):
def __init__(self) -> None:
super().__init__()
self.port = self.Port(TestBundle())


class TestInvalidOuter(Block):
def __init__(self) -> None:
super().__init__()
self.inner = self.Block(TestInner())
self.source = self.Block(TestBlockSource())
self.connect(self.inner.port.a, self.source.source)


class BundleInnerConnectError(unittest.TestCase):
def test_connect_error(self) -> None:
with self.assertRaises(UnconnectableError):
TestInvalidOuter()._elaborated_def_to_proto()
Loading