From 087ccf4503d0ad70167e5709d785def6acd669d0 Mon Sep 17 00:00:00 2001 From: Fedor Isakov Date: Wed, 14 Nov 2018 17:59:53 +0100 Subject: [PATCH] Fix matching single constraint on reactivation after a logical has been assigned. --- .../mps/logic/reactor/core/RuleMatcher.kt | 10 ++++++- reactor/Test/test/TestRuleMatcher.kt | 28 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/reactor/Core/src/jetbrains/mps/logic/reactor/core/RuleMatcher.kt b/reactor/Core/src/jetbrains/mps/logic/reactor/core/RuleMatcher.kt index 582a26dd..5ec07f87 100644 --- a/reactor/Core/src/jetbrains/mps/logic/reactor/core/RuleMatcher.kt +++ b/reactor/Core/src/jetbrains/mps/logic/reactor/core/RuleMatcher.kt @@ -82,10 +82,18 @@ class RuleMatcher(val rule: Rule) { } } - else -> newNodes.add(fn) + else -> { + newNodes.add(fn) + } } } + if (newNodes.size == 1) { + // only the root + val rfn = newNodes.get(0) + newNodes.addAll(rfn.expand(occ, genId + 1, rfn.matchingVacant(mask))) + } + return MatchFringe(newNodes, seen, genId + 1) } else { diff --git a/reactor/Test/test/TestRuleMatcher.kt b/reactor/Test/test/TestRuleMatcher.kt index d1337444..25680813 100644 --- a/reactor/Test/test/TestRuleMatcher.kt +++ b/reactor/Test/test/TestRuleMatcher.kt @@ -86,6 +86,34 @@ class TestRuleMatcher { } } + @Test + fun testSameOccurrenceLogical() { + with(programWithRules( + rule("rule1", + headReplaced( + constraint("foo", term("bar")) + ), + body( + constraint("qux") + )))) + { + val X = metaLogical("X") + val x = X.logical() + val foo = occurrence("foo", x) + with(ruleMatcher().probe()) { + + expand(foo) }.apply { + matches().size shouldBe 0 }.run { + + x.set(term("bar")) + + expand(foo) }.apply { + matches().size shouldBe 1 }.run { + + } + } + } + @Test fun testTermArgument() { with(programWithRules(