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

Aperta
#557 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@CatarinaGamboa ci sta già lavorando.

Dal 24/11/2026.

  • #559 di @CatarinaGamboa — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
30/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
java
Ambito
tooling

Direzione di ricerca

The bug is in RefinementTypeChecker.visitCtNewArray, which loops over the dimension expressions and keeps the last one, where it should keep the first. Start there and read the TODO about only working for one dimension. Done means length(_) of new int[2][3] resolves to 2, and the reproducer in the issue is rejected. Open pull request #559 already targets this, so check it before starting.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

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.

Lingua principale
Java
Stelle
73
Fork
38
Merge medio
12h 32m
PR unite (30g)
45

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di liquid-java/liquidjava

Tutte le issue di liquid-java/liquidjava

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.