Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Value Checker Reports @UnknownVal for Compound Assignment on Some Variables #121

Closed
zcai1 opened this issue Oct 27, 2021 · 0 comments · Fixed by #122
Closed

Value Checker Reports @UnknownVal for Compound Assignment on Some Variables #121

zcai1 opened this issue Oct 27, 2021 · 0 comments · Fixed by #122

Comments

@zcai1
Copy link
Collaborator

zcai1 commented Oct 27, 2021

Example:

import org.checkerframework.common.value.qual.*;
class A {
        @IntRange(from = 5, to = 10) int a;

        void foo1() {
            if (a == 5) {
                a += 5;
            }
        }

        void foo2(@IntRange(from = 5, to = 10) int b) {
            if (b == 5) {
                b += 5;
            }
        }
}

I expect the constant value checker to produce no errors, but it generates the following error messages:

error: [compound.assignment.type.incompatible] expression type incompatible with left-hand side in compound assignment.
                a += 5;
                  ^
  found   : @UnknownVal int
  required: @IntRange(from=5, to=10) int

error: [compound.assignment.type.incompatible] expression type incompatible with left-hand side in compound assignment.
                b += 5;
                  ^
  found   : @UnknownVal int
  required: @IntRange(from=5, to=10) int

As shown above, this issue happens to fields and method parameters. But if a was a local variable declared in the method body, then the checker will work as expected.

When a is a field, the corresponding CFG node is:

Before: CFStore#207(
 this.a > CFAV{@IntVal(5), int})
~~~~~~~~~
(this)   [ ImplicitThis ]
(this).a   [ FieldAccess ]    > CFAV{@IntVal(5), int}
5   [ IntegerLiteral ]    > CFAV{@IntVal(5), int}
((this).a + 5)   [ NumericalAddition ]    > CFAV{@IntVal(10), int}
(@org.checkerframework.common.value.qual.IntRange(from=5L, to=10L) int)((this).a + 5)   [ TypeCast ]    > CFAV{@UnknownVal, int}
(this).a = (@org.checkerframework.common.value.qual.IntRange(from=5L, to=10L) int)((this).a + 5)   [ Assignment ]    > CFAV{@UnknownVal, int}

When b is a method parameter, the corresponding CFG node is:

Before: CFStore#219(
 b > CFAV{@IntVal(5), int}
 this.a > CFAV{@IntRange(from=5, to=10), int})
~~~~~~~~~
b   [ LocalVariable ]    > CFAV{@IntVal(5), int}
5   [ IntegerLiteral ]    > CFAV{@IntVal(5), int}
(b + 5)   [ NumericalAddition ]    > CFAV{@IntVal(10), int}
(@org.checkerframework.common.value.qual.IntRange(from=5L, to=10L) int)(b + 5)   [ TypeCast ]    > CFAV{@UnknownVal, int}
b = (@org.checkerframework.common.value.qual.IntRange(from=5L, to=10L) int)(b + 5)   [ Assignment ]    > CFAV{@UnknownVal, int}

When a is a local variable declared in the method body, the corresponding CFG node is:

Before: CFStore#221(
 a > CFAV{@IntVal(5), int}
 c > CFAV{@IntRange(from=-2147483648, to=2147483647), int})
~~~~~~~~~
a   [ LocalVariable ]    > CFAV{@IntVal(5), int}
5   [ IntegerLiteral ]    > CFAV{@IntVal(5), int}
(a + 5)   [ NumericalAddition ]    > CFAV{@IntVal(10), int}
(int)(a + 5)   [ TypeCast ]    > CFAV{@IntVal(10), int}
a = (int)(a + 5)   [ Assignment ]    > CFAV{@IntVal(10), int}

Observe that the type changes after "TypeCast".

@zcai1 zcai1 changed the title Value Checker Reports @UnknownVal for Compound Assignment on Non-local Variables Value Checker Reports @UnknownVal for Compound Assignment on Some Variables Oct 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant