Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

Soundness: a local variable with a constant's name shadows the constant (Format.JPG read as local JPG)

Ouverte Adaptée aux débutants
#321 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
78/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
java
Domaine
testing

Piste de recherche

Commencez dans RefinementTypeChecker.visitCtFieldRead, identifié dans l’issue, et reproduisez le conflit de noms avec l’exemple Java fourni. Vérifiez comment la recherche dans le contexte distingue une variable locale du champ lu ; l’issue décrit un correctif possible et indique que les 347 tests passent. C’est terminé lorsque le reproducteur signale une erreur de refinement au niveau de onlyPng(g) et que la suite de tests passe toujours.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

bug

Description

A field read of a constant such as Format.JPG is resolved to a local variable with the same simple name (JPG), if one is in scope, instead of the constant. The refinement of the local is then used, so real violations are accepted.

Minimal reproducer

import liquidjava.specification.Refinement;

public class Repro {
    enum Format { JPG, PNG }

    static void onlyPng(@Refinement("_ == Format.PNG") Format f) {}

    public static void main(String[] args) {
        Format JPG = Format.PNG;       // a local that happens to share the constant's name
        Format g = Format.JPG;         // the enum constant JPG, not the local
        onlyPng(g);                    // expected error: g is JPG
    }
}

Expected

A refinement error at onlyPng(g): g holds Format.JPG.

Actual

Correct! Passed Verification.

Removing the line Format JPG = Format.PNG; gives the expected error (g == JPG is not a subtype of g == Format.PNG), so the name clash is what hides it.

Reproduced on main at fbfb4e23.

Where

RefinementTypeChecker.visitCtFieldRead: its first branch looks the field up by simple name in the context (where the local lives) without checking that the variable found is the field being read. A candidate fix (about 5 lines, found during the review of #319) only uses the context variable when it really is that field, and otherwise falls through; it keeps all 347 tests passing.

Context

Found by the adversarial review of #319 (fix for #302): with #319 the same clash inside an if condition (if (f == Format.JPG)) turns a former crash into an accepted violation, so this should be fixed before or with #319.

Langage dominant
Java
Étoiles
67
Forks
36
Merge moyen
2 j 9 h
PR mergées (30 j)
24

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de liquid-java/liquidjava

Toutes les issues de liquid-java/liquidjava

Issues similaires

Plus d'issues Java

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.