Skip to content

new T[a][b] gets length b instead of a (unsound) #557

In review

Description

@CatarinaGamboa

Description
A multi-dimensional array creation gets the length of its last dimension instead of its first, so wrong programs are accepted (unsound).

Minimal reproducer

import liquidjava.specification.Refinement;

public class Grid {
    static void rows(int[][] g, @Refinement("_ == length(g)") int n) {}

    public static void main(String[] args) {
        rows(new int[2][3], 3);   // length(g) is 2, should be rejected
    }
}

Result on main: Correct! Passed Verification.

Cause
RefinementTypeChecker.visitCtNewArray loops over the dimension expressions and keeps the last one (there is a "only working for 1 dimension" TODO there).

Expected
length(_) of new T[d1][d2]... is d1. Inner arrays are not modelled, so nothing should be assumed about them. Found while reviewing #540.

Activity

  1. added
    bug
    on Nov 24, 2026
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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions