Skip to content

Commit

Permalink
Disallow inner connects (#369)
Browse files Browse the repository at this point in the history
Adds a frontend error so it doesn't result in a confusing compiler
internal error.

Also fixes an unrelated type annotation issue flagged by a new version
of mypy.
  • Loading branch information
ducky64 authored Jul 25, 2024
1 parent 172a254 commit 9a64eef
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
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()

0 comments on commit 9a64eef

Please sign in to comment.