From c296e2e7c0ffda82e009986e3838c570c7972da5 Mon Sep 17 00:00:00 2001 From: Danilo Pianini Date: Mon, 13 May 2024 17:13:15 +0200 Subject: [PATCH] fix(engine): fix a bug in the removal of reactions with a global output context --- .../alchemist/core/JGraphTDependencyGraph.kt | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/alchemist-engine/src/main/kotlin/it/unibo/alchemist/core/JGraphTDependencyGraph.kt b/alchemist-engine/src/main/kotlin/it/unibo/alchemist/core/JGraphTDependencyGraph.kt index 32043f9094..68ba9c6f52 100644 --- a/alchemist-engine/src/main/kotlin/it/unibo/alchemist/core/JGraphTDependencyGraph.kt +++ b/alchemist-engine/src/main/kotlin/it/unibo/alchemist/core/JGraphTDependencyGraph.kt @@ -111,22 +111,22 @@ class JGraphTDependencyGraph(private val environment: Environment) : } override fun removeDependencies(reaction: Actionable) { - check(graph.removeVertex(reaction)) { - BugReporting.reportBug( - "Reaction does not exists in the dependency graph.", - mapOf( - "reaction" to reaction, - "graph" to graph, - "incarnation" to environment.incarnation, - "environment" to environment, - ), - ) - } - check(reaction.inputContext != Context.GLOBAL || inGlobals.remove(reaction)) { - "Inconsistent state: $reaction, with global input context, was not in the appropriate pool." - } - check(reaction.outputContext != Context.GLOBAL || !outGlobals.remove(reaction)) { - "Inconsistent state: $reaction, with global output context, was not in the appropriate pool." + fun bugInfo() = mapOf( + "reaction" to reaction, + "graph" to graph, + "incarnation" to environment.incarnation, + "environment" to environment, + ) + fun bug(message: String): Nothing = + BugReporting.reportBug(message, bugInfo()) + if (!graph.removeVertex(reaction)) { + bug("Reaction does not exists in the dependency graph.") + } + if (reaction.inputContext == Context.GLOBAL && !inGlobals.remove(reaction)) { + bug("Inconsistent state: $reaction, with global input context, was not in the appropriate pool.") + } + if (reaction.outputContext == Context.GLOBAL && !inGlobals.remove(reaction)) { + bug("Inconsistent state: $reaction, with global input context, was not in the appropriate pool.") } runtimeRemovalCache += reaction }