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(