apache / incubator-kie-drools

Drools is a rule engine, DMN engine and complex event processing (CEP) engine for Java.
http://www.drools.org
5.85k stars 2.49k forks source link

[new-parser] Broken named consequences inside OR #5945

Closed yurloc closed 4 months ago

yurloc commented 4 months ago

Parent issue

Failing tests

Notes

The new parser creates a slightly more flat descr structure compared to the old parser. I think that's the cause of the later compilation error.

Old parser output (expected)

lhs : [AND [[OR [[AND [[Pattern: id=$a; objectType=Cheese], do[t1]] ], [Pattern: id=$b; objectType=Cheese]] ], [Pattern: id=$c; objectType=Cheese]] ]
- 0 :       [OR [[AND [[Pattern: id=$a; objectType=Cheese], do[t1]] ], [Pattern: id=$b; objectType=Cheese]] ]
- 1 :                                                                                                          [Pattern: id=$c; objectType=Cheese]

Note that the first pattern $a : Cheese() and its consequence t1 are AND-connected ($a AND t1) OR $b.

New parser output (actual)

lhs : [AND [[OR [[Pattern: id=$a; objectType=Cheese], do[t1], [Pattern: id=$b; objectType=Cheese]] ], [Pattern: id=$c; objectType=Cheese]] ]
- 0 :       [OR [[Pattern: id=$a; objectType=Cheese], do[t1], [Pattern: id=$b; objectType=Cheese]] ]
- 1 :                                                                                                 [Pattern: id=$c; objectType=Cheese]

Flat OR structure connecting three elements ($a OR t1 OR $b).

Rule code snippet

rule R1 when
    ( $a: Cheese ( type == "stilton" ) do[t1] or $b: Cheese ( type == "gorgonzola" ) )
    $c: Cheese ( type == "cheddar" )
then
    results.add( $c.getType() );
then[t1]
    results.add( $a.getType() );
end

Error output

### parse : ANTLR4_PARSER_ENABLED = true
12:48:17.268 [main] ERROR o.d.c.k.b.impl.AbstractKieProject.buildKnowledgePackages:280 - Unable to build KieBaseModel:KieBaseModelName
Rule Compilation error : [Rule name='R1']
    $a cannot be resolved

12:48:17.269 [main] ERROR o.d.testcoverage.common.util.KieUtil.getKieBuilderFromKieFileSystem:165 - KieBuilder errors: [Message [id=1, kieBase=KieBaseModelName, level=ERROR, path=rules1.drl, line=4, column=0
   text=Rule Compilation error $a cannot be resolved]]

java.lang.AssertionError: [[Message [id=1, kieBase=KieBaseModelName, level=ERROR, path=rules1.drl, line=4, column=0
   text=Rule Compilation error $a cannot be resolved]]] 
Expecting empty but was: [Message [id=1, kieBase=KieBaseModelName, level=ERROR, path=rules1.drl, line=4, column=0
   text=Rule Compilation error $a cannot be resolved]]

    at org.drools.testcoverage.common.util.KieUtil.getKieBuilderFromKieFileSystem(KieUtil.java:169)
    at org.drools.testcoverage.common.util.KieUtil.getKieBuilderFromKieFileSystem(KieUtil.java:134)
    at org.drools.testcoverage.common.util.KieUtil.buildAndInstallKieModuleIntoRepo(KieUtil.java:78)
    at org.drools.testcoverage.common.util.KieUtil.buildAndInstallKieModuleIntoRepo(KieUtil.java:72)
    at org.drools.testcoverage.common.util.KieUtil.getKieModuleFromResources(KieUtil.java:249)
    at org.drools.testcoverage.common.util.KieUtil.getKieModuleFromResources(KieUtil.java:238)
    at org.drools.testcoverage.common.util.KieBaseUtil.getKieBaseFromKieModuleFromResources(KieBaseUtil.java:102)
    at org.drools.testcoverage.common.util.KieBaseUtil.getKieBaseFromKieModuleFromDrl(KieBaseUtil.java:115)
    at org.drools.mvel.integrationtests.EdgeCaseNonExecModelTest.executeTestWithDRL(EdgeCaseNonExecModelTest.java:105)
    at org.drools.mvel.integrationtests.EdgeCaseNonExecModelTest.testNamedConsequencesInsideOR1(EdgeCaseNonExecModelTest.java:73)
tkobayas commented 4 months ago

/take

tkobayas commented 4 months ago

Fixed by https://github.com/apache/incubator-kie-drools/pull/5950