Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad position in exception conflict #755

Open
AltGr opened this issue Dec 19, 2024 · 2 comments
Open

Bad position in exception conflict #755

AltGr opened this issue Dec 19, 2024 · 2 comments
Assignees
Labels
🔧 compiler Issue concerns the compiler ❓ invalid This doesn't seem right

Comments

@AltGr
Copy link
Contributor

AltGr commented Dec 19, 2024

I got a very confusing error on two conflicting exceptions, where the positions reported didn't match the actual issue. I failed to reproduce for now on a simplified example, but it can be seen on https://github.com/CatalaLang/poc-cnaf/tree/debugConflictPos with clerk test tests/fonctionnels/cas_1.catala_fr

In more detail, on the follwing piece of code:

champ d'application Barèmes:
  étiquette base
  définition taux_majoration_montant_forfaitaire
      de isolement, rôle
    sous condition isolement sous forme Isolé et
                   rôle sous forme PersonneÀCharge de n et n = 1
    conséquence égal à 50%

  étiquette base
  définition taux_majoration_montant_forfaitaire
      de isolement, rôle
    sous condition isolement sous forme Isolé et
                   rôle sous forme PersonneÀCharge de n et n = 2
    conséquence égal à 30%  # <=== position 1

  étiquette base
  définition taux_majoration_montant_forfaitaire
      de isolement, rôle
    sous condition isolement sous forme Isolé et
                   rôle sous forme PersonneÀCharge de n et n > 2
    conséquence égal à 40% # <=== position 2

  étiquette base
  définition taux_majoration_montant_forfaitaire
      de isolement, rôle
    sous condition isolement sous forme Couple et
                   rôle sous forme Conjoint
    conséquence égal à 50%

  étiquette base
  définition taux_majoration_montant_forfaitaire
      de isolement, rôle
    sous condition isolement sous forme Couple et
                   rôle sous forme PersonneÀCharge de n et n = 1
    conséquence égal à 30%

  étiquette base
  définition taux_majoration_montant_forfaitaire
      de isolement, rôle
    sous condition isolement sous forme Couple et
                   rôle sous forme PersonneÀCharge de n et n = 2
    conséquence égal à 30%

  étiquette base
  définition taux_majoration_montant_forfaitaire
      de isolement, rôle
    sous condition isolement sous forme Couple et
                   rôle sous forme PersonneÀCharge de n et n > 1
    conséquence égal à 40%

we get:

┌─[ERROR]─
│
│  During evaluation: conflict between multiple valid consequences for assigning the same variable.
│
├─➤ src/rsa.catala_fr:348.24-348.27:
│     │
│ 348 │     conséquence égal à 30%
│     │                        ‾‾‾
├─ Brique 4 : calcul du Revenu de Solidarité Active (RSA)
│  └─ les barèmes RSA
│
├─➤ src/rsa.catala_fr:355.24-355.27:
│     │
│ 355 │     conséquence égal à 40%
│     │                        ‾‾‾
└─ Brique 4 : calcul du Revenu de Solidarité Active (RSA)
   └─ les barèmes RSA

The issue is that the two positions referred to are as marked with comments on the source, and it's pretty clear that they cannot conflict. The actual issue is between the two last cases, because of a typo in the last one.
The issue likely comes from the tweak that merges condition with syntactically identical outcomes, to avoid spurious conflicts...

As an additional feature wish: when a conflict happens, it would be extremely useful for debugging to know what inputs the conflict happened on. This is non-trivial, we would need to

  1. extract the free variables in the conditions to get the relevant information, at compile time
  2. at runtime, output the values of these variables when a conflict (or a missing definition error) happens
AltGr added a commit that referenced this issue Dec 20, 2024
@AltGr
Copy link
Contributor Author

AltGr commented Dec 20, 2024

Added a test illustrating this in f38f2b2

Interstingly, the issue is not triggered on dcalc, but appears on interpret --lcalc, and disappears again with -O

@AltGr
Copy link
Contributor Author

AltGr commented Dec 20, 2024

The issue is that the term (in unoptimised lcalc) is a match of the form:

           match
             (match if case = 6 then ESome 0.3 else ENone () with
              | ENone → if case = 5 then ESome 0.3 else ENone ()
              | ESome x → ESome x)
           with
           | ENone → if case = 2 then ESome 0.3 else ENone ()
           | ESome x → ESome x;

where the ESome x -> ESome x, rebuilding the original term unchanged, lose its original position information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔧 compiler Issue concerns the compiler ❓ invalid This doesn't seem right
Projects
Status: In Progress
Development

No branches or pull requests

2 participants