Skip to content

False error: comparing with a char literal other than a lowercase letter, digit or _ ('[', 'Z', ' ') is rejected as an invalid refinement expression #444

Closed

Description

@CatarinaGamboa

Impact: correct client code is rejected with a syntax error whenever it compares a char with a literal like '[', '{', ',', ' ' or 'Z', which is the everyday code of parsers and tokenizers. No annotations are involved. This is related to #398 (escaped literals such as '\r'), but it is broader: plain punctuation, the space and uppercase letters fail too.

Minimal reproducer

public class Repro {
    static int skipTo(String s) {
        int i = 0;
        while (s.charAt(i) != '[')
            i++;
        return i;
    }
}

Expected: Correct! Passed Verification.

Actual (main @ f7f366c, and 1a506fe):

Syntax Error: Invalid refinement expression, expected a logical predicate

Which literals fail. return s.charAt(i) == C; was tried for each literal C:

passes fails
'a', 'x', '0', '9', '_' 'Z', ' ', and every punctuation character tried: [ ] { } ( ) , < " # $ | & ! = + * / % ^ ? : ; . - @ ~

The ones that pass are exactly the characters that can start an ID or an INT in RJ.g4, which has no char-literal token. That suggests the literal reaches the refinement parser as text. If so, '0' "passing" may also give it the value 0 rather than 48. I haven't checked that.

Real-world scenario. I found this while checking real client code against a java.io.BufferedReader spec. Two methods from FrancescoBorzi/Esercizi-Tecniche-di-Programmazione-Concorrente-e-Distribuita (es05.java, es11.java) read an HTTP response with readLine() and then scan it for a bracket:

BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream()));
...
msg = "";
while ((tmp = in.readLine()) != null)
    msg += tmp;

i = 0;
while (msg.charAt(i) != '[')     // Syntax Error here
    i++;

The reader is used correctly, but the method can't be verified at all, so the typestate check of in never happens. JSON and CSV tokenizers (c == '{', c == ',', c == ' ') hit the same error.

Activity

  1. added a commit that references this issue on Oct 29, 2026
    19991d3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions