barry-m / checker-framework

Automatically exported from code.google.com/p/checker-framework
Other
0 stars 0 forks source link

Regex Checker: flow refinement based on Matcher.groupCount() #291

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The Regex Checker should support flow refinements based on Matcher.groupCount() 
checks:

if (mat.matches()) {
    if (mat.groupCount() > 0) {
        System.out.println("Group: " + mat.group(1));
    }
}

The call of mat.group(1) is guaranteed to succeed by the guards.
The Checker currently reports an error:

MatcherGroupCount.java:22: error: invalid groups parameter 1. Only 0 groups are 
guaranteed to exist for mat.
                System.out.println("Group: " + mat.group(1));
                                                         ^
1 error

A test file is in checker-framework/checkers/tests/regex/MatcherGroupCount.java

(For bonus points: the Regex Checker currently only recognizes int literals; 
once the Value Checkers are integrated, this could be extended accordingly.)

Original issue reported on code.google.com by wdi...@gmail.com on 14 Dec 2013 at 6:59

GoogleCodeExporter commented 9 years ago

Original comment by wdi...@gmail.com on 22 Dec 2013 at 7:36