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: [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]