Incorrect Result in Collection Attribute Evaluation with Circular `when` Condition and Circular Evaluation
Issue #338
new
Issue Summary:
The collection attributes in JastAdd are computing incorrect results when the when
condition is/depends on a circular attribute and the attributes are called within a circular evaluation. This issue arises specifically when using the --safeLazy
option, as the attribute is cached too early.
The problem appears only when using --safeLazy
.
Example:
Given the following RAG specification:
//Grammar: Root;
//Options: --rewrite=cnta --visitCheck=false --safelazy
syn Set<Integer> Root.numbers() circular [new HashSet<Integer>()] {
return collectNumbers();
}
coll Set<Integer> Root.collectNumbers() [new HashSet<Integer>()];
Root contributes 42 when alwaysTrue() to Root.collectNumbers();
syn boolean Root.alwaysTrue() = circ() == 4;
syn Integer Root.circ() circular [0] {
Integer temp = circ()+1;
System.out.println("temp: " + temp);
return Math.min(4, temp);
}
The expected output of the following Java program
public class Test {
public static void main(String[] args) {
Root r = new Root();
System.out.println(r.numbers());
}
}
should be:
temp: 1
temp: 2
temp: 3
temp: 4
temp: 5
temp: 5
[42]
The actual result is:
temp: 1
[]