tkobayas commented on code in PR #6786:
URL:
https://github.com/apache/incubator-kie-drools/pull/6786#discussion_r3496775270
##########
drools-model/drools-model-codegen/src/main/java/org/drools/model/codegen/execmodel/generator/RuleContext.java:
##########
@@ -316,15 +316,15 @@ public Optional<MethodCallExpr> findBindingExpression(
String boundVar ) {
public void addGlobalDeclarations() {
Map<String, java.lang.reflect.Type> globals = getGlobals();
- // also takes globals defined in different packages imported with a
wildcard
- packageModel.getImports().stream()
- .filter( imp -> imp.endsWith(".*") )
- .map( imp -> imp.substring(0, imp.length()-2) )
- .map( imp -> typeDeclarationContext.getPackageRegistry(imp) )
+ // Globals are kbase-wide: include globals declared in any package of
the kbase, not only
+ // those in the current package or in packages imported with a
wildcard. This matches the
+ // classic (non-executable-model) behavior where a global is visible
from every package, so
+ // a constraint can reference a global declared in another DRL without
a wildcard import.
+ typeDeclarationContext.getPackageRegistry().values().stream()
.filter( Objects::nonNull )
- .map( pkgRegistry -> pkgRegistry.getPackage().getGlobals() )
- .forEach( globals::putAll );
-
+ .filter( pkgRegistry -> pkgRegistry.getPackage() != null )
+ .forEach( pkgRegistry -> globals.putAll(
pkgRegistry.getPackage().getGlobals() ) );
+
Review Comment:
Thank you for this PR, @drccrd
"`addGlobalDeclarations()` mutates the Map returned by
`RuleContext.getGlobals()`" is a pre-existing bug. It would be great if you
could also address it as Copilot suggested by making `RuleContext.getGlobals()`
return a defensive copy built from `typeDeclarationContext.getGlobals()` plus
unit-specific entries. This ensures that `RuleContext.getGlobals()`
consistently exposes KieBase-wide globals across all its callers, while also
avoiding the scanning since `typeDeclarationContext.getGlobals()` already
contains the KieBase-wide globals.
WDYT?
--
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]