You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kie.apache.org by "drccrd (via GitHub)" <gi...@apache.org> on 2026/06/29 15:40:33 UTC

[I] Executable model: a result constraint referencing an inline `accumulate` binding fails to compile (binding typed as `Object`) [incubator-kie-drools]

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

   **Summary:** For an inline-binding accumulate `accumulate( …; $b : fn(…); <constraint using $b> )`, a result constraint that uses the binding (e.g. `$b.size > 0`) fails to compile because `$b` is typed as `Object` in the generated constraint lambda, so member access doesn't resolve. The classic compiler types the binding as the accumulate function's result type.
   
   **Reproducer** (`Person` with `int getAge()`):
   ```drl
   import org.test.Person;
   rule R when
     accumulate(
       $p : Person( $a : age );
       $ages : collectList( $a );
       $ages.size > 0
     )
   then end
   ```
   - **Expected:** compiles (`$ages` typed as `List`).
   - **Actual:** compile error — `size` cannot be resolved; generated lambda is `(Object $ages) -> $ages.size > 0`.
   
   **Root cause:** the result pattern correctly keeps its `Object` object-type node (for RETE matching), but the constraint lambdas built for the result constraints are not retyped to the function's result type. *(Naively changing the pattern's object type instead breaks RETE matching — it caused ~28 AccumulateTest/GroupByTest failures — so only the constraint lambdas must be retyped, not the OTN.)*
   
   **Suggested fix:** after building the result pattern, retype the binding references in the already-built constraint expressions to the accumulate function's result type, leaving the pattern object type unchanged (in `ModelGeneratorVisitor`, inline-binding accumulate branch):
   ```java
   context.getTypedDeclarationById(function.getBind())
       .map(DeclarationSpec.class::cast)
       .ifPresent(decl -> {
           Class<?> resultType = decl.getDeclarationClass();
           if (resultType != null && resultType != Object.class)
               context.getExpressions().forEach(e ->
                   replaceTypeInExprLambdaAndIndex(decl.getBindingId(), resultType, e));
       });
   ```


-- 
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: commits-unsubscribe@kie.apache.org.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org


Re: [I] Executable model: a result constraint referencing an inline `accumulate` binding fails to compile (binding typed as `Object`) [incubator-kie-drools]

Posted by "tkobayas (via GitHub)" <gi...@apache.org>.
tkobayas closed issue #6783: Executable model: a result constraint referencing an inline `accumulate` binding fails to compile (binding typed as `Object`)
URL: https://github.com/apache/incubator-kie-drools/issues/6783


-- 
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: commits-unsubscribe@kie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org


Re: [I] Executable model: a result constraint referencing an inline `accumulate` binding fails to compile (binding typed as `Object`) [incubator-kie-drools]

Posted by "tkobayas (via GitHub)" <gi...@apache.org>.
tkobayas commented on issue #6783:
URL: https://github.com/apache/incubator-kie-drools/issues/6783#issuecomment-4998244177

   fixed by https://github.com/apache/incubator-kie-drools/pull/6791


-- 
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: commits-unsubscribe@kie.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@kie.apache.org
For additional commands, e-mail: commits-help@kie.apache.org