Fix matching single constraint on reactivation after a logical has been assigned.

This commit is contained in:
Fedor Isakov 2018-11-14 17:59:53 +01:00
parent fc7b9d6caf
commit 087ccf4503
2 changed files with 37 additions and 1 deletions

View File

@ -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 {

View File

@ -86,6 +86,34 @@ class TestRuleMatcher {
}
}
@Test
fun testSameOccurrenceLogical() {
with(programWithRules(
rule("rule1",
headReplaced(
constraint("foo", term("bar"))
),
body(
constraint("qux")
))))
{
val X = metaLogical<Term>("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(