Skip to content

False Positive With Early Return #68

Closed

Description

@rcosta358

The type checker fails to recognize that an early return can satisfy a refinement condition.

public class Example {

    public static int divide(int a, @Refinement("b != 0") int b) {
        return a / b;
    }

    public static void example1(int x, int y) {
        if (y == 0) {
            System.out.println("division by zero");
        } else {
            divide(x, y); // correct (no error)
        }
    }

    public static void example2(int x, int y) {
        if (y == 0) {
            System.out.println("division by zero");
            return; // early return
        }
        divide(x, y); // should also be correct but isnt
    }
}

In this example, the refinement b != 0 should be considered satisfied in both cases, since after the if (y == 0) branch returns, the only reachable path ensures y != 0.

Possible Fix

Convert early-exit branches into ternary (explicit if-else).

Activity

  1. self-assigned this
    on Oct 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions