diff --git a/pynestml/cocos/co_co_each_block_defined_at_most_once.py b/pynestml/cocos/co_co_each_block_defined_at_most_once.py index 66b479c18..1fd6d2bf7 100644 --- a/pynestml/cocos/co_co_each_block_defined_at_most_once.py +++ b/pynestml/cocos/co_co_each_block_defined_at_most_once.py @@ -48,30 +48,12 @@ def check_co_co(cls, node: ASTModel): Checks whether each block is define at most once. :param node: a single neuron or synapse. """ - if len(node.get_state_blocks()) > 1: - code, message = Messages.get_block_not_defined_correctly('State', False) - Logger.log_message(code=code, message=message, node=node, error_position=node.get_source_position(), - log_level=LoggingLevel.ERROR) # check that update block is defined at most once if len(node.get_update_blocks()) > 1: code, message = Messages.get_block_not_defined_correctly('Update', False) Logger.log_message(code=code, message=message, node=node, error_position=node.get_source_position(), log_level=LoggingLevel.ERROR) - # check that parameters block is defined at most once - if len(node.get_parameters_blocks()) > 1: - code, message = Messages.get_block_not_defined_correctly('Parameters', False) - Logger.log_message(code=code, message=message, node=node, error_position=node.get_source_position(), - log_level=LoggingLevel.ERROR) - # check that internals block is defined at most once - if len(node.get_internals_blocks()) > 1: - code, message = Messages.get_block_not_defined_correctly('Internals', False) - Logger.log_message(code=code, message=message, node=node, error_position=node.get_source_position(), - log_level=LoggingLevel.ERROR) - # check that equations block is defined at most once - if len(node.get_equations_blocks()) > 1: - code, message = Messages.get_block_not_defined_correctly('Equations', False) - Logger.log_message(code=code, message=message, node=node, error_position=node.get_source_position(), - log_level=LoggingLevel.ERROR) + # check that input block is defined at most once if len(node.get_input_blocks()) > 1: code, message = Messages.get_block_not_defined_correctly('Input', False) @@ -81,6 +63,7 @@ def check_co_co(cls, node: ASTModel): code, message = Messages.get_block_not_defined_correctly('Input', True) Logger.log_message(code=code, message=message, node=node, error_position=node.get_source_position(), log_level=LoggingLevel.WARNING) + # check that output block is defined at most once if len(node.get_output_blocks()) > 1: code, message = Messages.get_block_not_defined_correctly('Output', False) diff --git a/pynestml/utils/messages.py b/pynestml/utils/messages.py index ef4d62207..0a6093ac5 100644 --- a/pynestml/utils/messages.py +++ b/pynestml/utils/messages.py @@ -552,24 +552,22 @@ def get_continuous_input_port_specified(cls, name, keyword): return MessageCode.CONTINUOUS_INPUT_PORT_WITH_QUALIFIERS, message @classmethod - def get_block_not_defined_correctly(cls, block, missing): + def get_block_not_defined_correctly(cls, block: str, missing: bool) -> Tuple[MessageCode, str]: """ Indicates that a given block has been defined several times or non. :param block: the name of the block which is not defined or defined multiple times. - :type block: str :param missing: True if missing, False if multiple times. - :type missing: bool - :return: a message - :rtype: (MessageCode,str) """ assert (block is not None and isinstance(block, str)), \ '(PyNestML.Utils.Message) Not a string provided (%s)!' % type(block) assert (missing is not None and isinstance(missing, bool)), \ '(PyNestML.Utils.Message) Not a bool provided (%s)!' % type(missing) + if missing: message = block + ' block not defined!' else: message = block + ' block defined more than once!' + return MessageCode.BLOCK_NOT_CORRECT, message @classmethod diff --git a/tests/nest_tests/resources/multiple_state_and_parameter_blocks.nestml b/tests/nest_tests/resources/multiple_state_and_parameter_blocks.nestml new file mode 100644 index 000000000..cb358d271 --- /dev/null +++ b/tests/nest_tests/resources/multiple_state_and_parameter_blocks.nestml @@ -0,0 +1,12 @@ +model multiple_state_and_parameter_blocks: + parameters: + a integer = 42 + + state: + x integer = a + + parameters: + b integer = a * x + + state: + y integer = a * x * b