Incorrect definite unassignment check

Issue #88 resolved
Jesper Öqvist created an issue

JastAddJ 7.1.1-263-g1cc8abc Java SE 7

According to JLSv3 16.1.7, a variable V is definitely (un)assigned after a boolean expression when true or false if it is (un)assigned after the expression. There is a bug in JastAddJ where this is not correctly computed. For example, the following is accepted by JastAddJ despite a double assignment to final:

final int v;
if ((v=3)==2 || (v=2)==3) ;

The error is caused by the equation for definite assignment after true/false for boolean expressions. Diff for the fix is below:

-  eq Expr.isDUafterFalse(Variable v) {
-    if(isTrue())
-      return true;
-    return isDUbefore(v);
-  }
-  //= isFalse() && isDUbefore(v) || isTrue();
-  eq Expr.isDUafterTrue(Variable v) {
-    if(isFalse())
-      return true;
-    return isDUbefore(v);
-  }
+  // JLSv3 16.1.7
+  eq Expr.isDUafterFalse(Variable v) = isTrue() || isDUafter(v);
+  eq Expr.isDUafterTrue(Variable v) = isFalse() || isDUafter(v);

Comments (4)

  1. Jesper Öqvist reporter

    Actually, the definite assignedness after true/false checks look incorrect. Diff against what they probably should be:

    -  eq Expr.isDAafterFalse(Variable v) = isTrue() || isDAbefore(v);
    -  eq Expr.isDAafterTrue(Variable v) = isFalse() || isDAbefore(v);
    +  eq Expr.isDAafterFalse(Variable v) = isTrue() || isDAafter(v);
    +  eq Expr.isDAafterTrue(Variable v) = isFalse() || isDAafter(v);
    

    This is difficult to find a test case to check.

  2. Log in to comment