diff --git a/lib/src/references/port_reference.dart b/lib/src/references/port_reference.dart index 5d61763..c72b0a7 100644 --- a/lib/src/references/port_reference.dart +++ b/lib/src/references/port_reference.dart @@ -135,9 +135,10 @@ sealed class PortReference extends Reference { } if (relativeLocation == _RelativePortLocation.sameModule && - direction == PortDirection.input) { + direction == PortDirection.input && + other.direction == PortDirection.input) { throw RohdBridgeException( - 'An port $other on module ${other.module} cannot drive an' + 'An input port $other on module ${other.module} cannot drive an' ' input $this on the same module'); } @@ -275,7 +276,13 @@ sealed class PortReference extends Reference { } } - return (driver: other._internalPort, receiver: _internalPort); + if (direction == PortDirection.input && + other.direction == PortDirection.output) { + // loop-back + return (driver: other._externalPort, receiver: _externalPort); + } else { + return (driver: other._internalPort, receiver: _internalPort); + } case _RelativePortLocation.sameLevel: return (driver: other._externalPort, receiver: _externalPort); @@ -322,7 +329,13 @@ sealed class PortReference extends Reference { } } - return other._internalPortSubset; + if (direction == PortDirection.input && + other.direction == PortDirection.output) { + // loop-back + return other._externalPortSubset; + } else { + return other._internalPortSubset; + } case _RelativePortLocation.sameLevel: return other._externalPortSubset; diff --git a/test/intf_port_module_port_connections_test.dart b/test/intf_port_module_port_connections_test.dart index 9853fed..d5777ab 100644 --- a/test/intf_port_module_port_connections_test.dart +++ b/test/intf_port_module_port_connections_test.dart @@ -192,7 +192,8 @@ void main() { if (testCase.relativePosition == _RelativePosition.sameModule && - testCase.dst.direction == PortDirection.input) { + testCase.dst.direction == PortDirection.input && + testCase.src.direction == PortDirection.input) { // port cant drive input on same module expectFailure = true; }