In that case, what we would see is that on exit, neither i nor j were either DA or DU, and we would issue a compiler error.  For each field, there are three possibilities:

 - The field is DU on all paths out of the ctor; we initialize it from the corresponding parameter.
 - The field is DA on all paths out of the ctor; we do nothing.
 - The field is neither DU nor DA on some path out of the ctor; error.

We could extend this analysis to the init block, where if its either of the first two cases, we feed that information back into the ctor analysis, and always error in the third case -- the real question is whether its worth the bother.


On 9/5/2019 8:43 PM, John Rose wrote:
On Sep 5, 2019, at 4:47 PM, Vicente Romero <[email protected]> wrote:
right I was thinking about the case:

record R(int i, int j) {
     public R {  // compact constructor
         if (i < 0) {
             this.i = -i;
         } else {
             this.j = j;
         }
     }
}
Correct me if I’m wrong, but we can cover cases like this by assigning to the 
component parameters, and let the fields get written automatically:

record R(int i, int j) {
     public R {  // compact constructor
         if (i < 0) {
             i = -i;  // not this.i
         } else {
             j = i+j;  // not this.j
         }
     }
}


Reply via email to