drccrd commented on code in PR #6786:
URL: 
https://github.com/apache/incubator-kie-drools/pull/6786#discussion_r3524602899


##########
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:
   @tkobayas I added the globals into t a copied variable to prevent mutation - 
but this to the fact that corss-package globals were no longer accessible - the 
map mutation was seeding globals across packages. Potentially intnetionally but 
intransparently.
   I added a global seeder in PackageModel. I considered it this was the right 
choice because it is now alling all globals to all packages - but I couldn't 
find a better place for it an the nature of globals is that they are available 
everywhere anyway.
   Do you see any problem/improvement?



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