drccrd opened a new issue, #6781:
URL: https://github.com/apache/incubator-kie-drools/issues/6781

   **Summary:** Under `ExecutableModelProject`, a `global` declared in one 
DRL/package and referenced in a pattern constraint in another DRL/package of 
the same KieBase fails to compile, although the classic compiler resolves it. 
Globals in Drools are KieBase-wide, but the exec model only collected globals 
from the rule's own package and packages imported with a wildcard.
   
   **Reproducer** (`Person` = any POJO with a `BigDecimal getMoney()`):
   ```drl
   // globals.drl
   package org.test.globals;
   global java.math.BigDecimal threshold;
   
   // rules.drl
   package org.test.rules;
   import org.test.Person;
   rule R when
     Person( money.compareTo(threshold) < 0 )
   then end
   ```
   - **Expected:** compiles (as in classic mode).
   - **Actual:** build error — *"Unable to Analyse Expression 
money.compareTo(threshold)"* (`threshold` not in scope).
   
   **Root cause:** `RuleContext.addGlobalDeclarations()` collected globals only 
from the current package plus packages imported via wildcard (`import x.*`).
   
   **Suggested fix:** collect globals from every package registry in the 
KieBase:
   ```java
   typeDeclarationContext.getPackageRegistry().values().stream()
       .filter(Objects::nonNull)
       .filter(reg -> reg.getPackage() != null)
       .forEach(reg -> globals.putAll(reg.getPackage().getGlobals()));
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to