UIMA-6405: Local variable not captured properly in a wildcard matching condition

- do not reset temp label vars in failed lookahead
diff --git a/ruta-core/src/main/java/org/apache/uima/ruta/rule/AbstractRuleElement.java b/ruta-core/src/main/java/org/apache/uima/ruta/rule/AbstractRuleElement.java
index f85c809..6b99ab1 100644
--- a/ruta-core/src/main/java/org/apache/uima/ruta/rule/AbstractRuleElement.java
+++ b/ruta-core/src/main/java/org/apache/uima/ruta/rule/AbstractRuleElement.java
@@ -126,8 +126,8 @@
     return result;

   }

 

-  protected void doneMatching(RuleMatch ruleMatch, RuleApply ruleApply, RutaStream stream,

-          InferenceCrowd crowd) {

+  protected void doneMatching(RuleMatch ruleMatch, RuleApply ruleApply, RuleElement entryPoint,

+          RutaStream stream, InferenceCrowd crowd) {

     if (!ruleMatch.isApplied()) {

       ruleApply.add(ruleMatch, stream);

       RutaRule rule = ruleMatch.getRule();

@@ -135,7 +135,8 @@
       if (ruleMatch.matchedCompletely()) {

         rule.getEnvironment().acceptTempVariableValues(localVariables);

         rule.getRoot().applyRuleElements(ruleMatch, stream, crowd);

-      } else {

+      } else if (entryPoint == null) {

+        // there was no dynamic lookahead, remove temp vars

         rule.getEnvironment().clearTempVariables(localVariables);

       }

       ruleMatch.setApplied(true);

diff --git a/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java b/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java
index e25038b..a38318c 100644
--- a/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java
+++ b/ruta-core/src/main/java/org/apache/uima/ruta/rule/ComposedRuleElement.java
@@ -534,7 +534,7 @@
 

     // take care that failed matches wont be applied

     ruleMatch.setMatched(ruleMatch.matched && !failed);

-    doneMatching(ruleMatch, ruleApply, stream, crowd);

+    doneMatching(ruleMatch, ruleApply, entryPoint, stream, crowd);

     return asList(ruleMatch);

   }

 

diff --git a/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java b/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java
index f616ab7..d4abcc6 100644
--- a/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java
+++ b/ruta-core/src/main/java/org/apache/uima/ruta/rule/RutaRuleElement.java
@@ -110,7 +110,7 @@
               result.addAll(fallbackContinue);

             } else if (getContainer() instanceof RuleElementIsolator) {

               // TODO move and refactor this:

-              doneMatching(extendedMatch, ruleApply, stream, crowd);

+              doneMatching(extendedMatch, ruleApply, entryPoint, stream, crowd);

             }

           }

         }

@@ -322,7 +322,7 @@
           result.addAll(fallbackContinue);

         } else {

           // should never happen!

-          doneMatching(ruleMatch, ruleApply, stream, crowd);

+          doneMatching(ruleMatch, ruleApply, entryPoint, stream, crowd);

         }

       }

     }

@@ -335,8 +335,7 @@
           InferenceCrowd crowd) {

     RuleElementMatch result = new RuleElementMatch(this, containerMatch);

     result.setRuleAnchor(ruleAnchor);

-    List<EvaluatedCondition> evaluatedConditions = new ArrayList<>(

-            conditions.size());

+    List<EvaluatedCondition> evaluatedConditions = new ArrayList<>(conditions.size());

     // boolean base = matcher.match(annotation, stream, getParent());

     boolean base = true;

     MatchContext context = new MatchContext(annotation, this, ruleMatch, after);

diff --git a/ruta-core/src/test/java/org/apache/uima/ruta/rule/WildCard2Test.java b/ruta-core/src/test/java/org/apache/uima/ruta/rule/WildCard2Test.java
index af6f5b4..03bd641 100644
--- a/ruta-core/src/test/java/org/apache/uima/ruta/rule/WildCard2Test.java
+++ b/ruta-core/src/test/java/org/apache/uima/ruta/rule/WildCard2Test.java
@@ -316,6 +316,11 @@
     CAS cas = RutaTestUtils.getCAS(document, complexType, featureMap);

     Ruta.apply(cas, script);

 

+    if (RutaTestUtils.DEBUG_MODE) {

+      RutaTestUtils.storeTypeSystem(complexType, featureMap);

+      RutaTestUtils.storeCas(cas, "testLookaheadWithFeatureMatch");

+    }

+

     RutaTestUtils.assertAnnotationsEquals(cas, 1, 1, "4");

     RutaTestUtils.assertAnnotationsEquals(cas, 2, 2, "2", "4");

   }