quickcheck icon indicating copy to clipboard operation
quickcheck copied to clipboard

Negating an integer leads to stack overflow

Open Heroglyph opened this issue 3 years ago • 2 comments

MWE:

use quickcheck::quickcheck;

#[test]
fn negate_value() {
    fn prop(i: i8) -> bool {
        -i;
        true
    }
    
    quickcheck(prop as fn(i8) -> bool);
}

I think that quickcheck tests this function with the smallest integer, which panics because it cannot be negated due to two's complement. So far, so correct. The resulting panic is then caught and correctly interpreted to be caused by a failed test. However, attempting to shrink the value causes another panic, which causes another attempt at shrinking, causing another panic and so on, ultimately resulting in a stack overflow as the shrinking functions pile on top of each other. This seems to be a bug in the way that shrinking is done (because it keeps testing the same value). How do we proceed?

Heroglyph avatar Oct 01 '21 14:10 Heroglyph

The endless recursion is likely a symptom of i8's shrinker yielding the original value. See #295 for a related issue.Could you check whether #296 resolves your issue?

neithernut avatar Oct 01 '21 15:10 neithernut

I checked by trying the current BurntShushi:master and neithernut:i32min-shrink-bound (revision 0c279d6). The latter revision (yours), fixed the issue, so merging the pull request should resolve my problem. Thank you!

Heroglyph avatar Oct 01 '21 17:10 Heroglyph